473,326 Members | 2,134 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,326 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 11489
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.