473,385 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Move files by date

2
Hello,

How can I move files based on age in the following scenario:

$SOURCE contains some subfolders with some files inside them.

Each subfolder contain files of the same date, but the last modofication date of the subfolder can be more recent than the date of the files inside it, e.g.:

$tree . -D
.
|-- [Feb 18 16:44] Folder1
| |-- [Feb 3 3:58] 1.jpg
| |-- [Feb 3 3:58] 2.avi
| `-- [Feb 3 3:58] 3.jpg
`-- [Feb 18 16:44] Folder2
|-- [Jan 29 3:33] a.jpg
|-- [Jan 29 3:33] b.jpg
|-- [Jan 29 3:33] c.avi
`-- [Jan 29 3:34] d.avi

If I try to move only the files newer than 15 days (today is Feb 18) with the following command, I get all the entire tree because it seems is just reading the date on the folders not on the files.

find $SOURCE -mtime -15 -exec mv {} $DEST \;

So, I want to move the files and the folders that contains the files to $DEST.
Feb 18 '09 #1
2 11496
numberwhun
3,509 Expert Mod 2GB
@xavix
You might have to write a bit more code to be a bit more specific with what you want. Since $SOURCE contains the list of directories, it is using the dates on those as the comparison to mtime. What you are not telling it to do is go into the directories by using the --depth option to find. Also, I would have to check and see if find has an option to not act on directories themselves.

Regards,

Jeff
Feb 18 '09 #2
xavix
2
Hi Jeff,

$SOURCE is something like /mnt/data/

I played around -depth and the option that only copy the wanted files is "-mindepth 2". What happens now is that "find $SOURCE -mindepth 2 -mtime -15 -exec mv {} $DEST \;" copies the files but not the folders that contains such files.

Probably you are right and should write more code than a simply find command

Thanks!
Feb 19 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ...
1
by: CPNZ | last post by:
I have a database i am m oving to another server, during the process I am moving the data and log files to another drive.(Which I have done countless times before with no problems) The problem I...
5
by: deko | last post by:
I have a subform datasheet that contains a full year of records sorted by a date field. I'm trying to programmatically move the record selector on the datasheet to the first record that matches a...
2
by: Eje | last post by:
I have a webapplication on a server. One function is to build txt-files. These files should then be moved to a fixed directory on another computer in the company network. I have tried to use...
1
by: Matthew Eno | last post by:
I have a problem where I'm developing some code that moves files from one place to another (on the same drive) with the destination file having a new name. What's happening is that the line of...
3
by: Arpan | last post by:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls. Using the FileUpload control, I want to give users the provision to move & delete files that DO NOT exist in C:\Inetpub\wwwroot...
3
by: jaeden99 | last post by:
I was wandering if nyone has a script to move files older than x days old? i've seen several to delete, but I don't want to delete. I would like to create a backup of the files first verify with...
8
by: inFocus | last post by:
Hello, I am new to python and wanted to write something for myself where after inputing two words it would search entire drive and when finding both names in files name would either copy or move...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.