Copy files by date title

Andrew Doades
Andrew Doades used Ask the Experts™
on
Hi,

I need a ruby script that will copy files from one place to another by the date in the filename.

What I have is files 'File_server_full_2010070200.7z'

The problem is I also have other files named differently, so I need to run this against all files that are like

"File_%_FULL_20100702%.7z"

Is this possible? Can anyone help!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CEO/Programmer
Commented:
there are different way doing it.
e.g you can use
DirDir["File_server_full_20100702*"]

with the following filessfrido@fxen:~/programming/ruby/experts_exchange/Q_26302995% ls -l *
-rw-rw-r-- 1 frido frido 0  5. Jul 13:15 File_server_full_2010070200.7z
-rw-rw-r-- 1 frido frido 0  5. Jul 13:15 File_server_full_2010070201.7z
-rw-rw-r-- 1 frido frido 0  5. Jul 13:17 File_server_full_2010070301.7z

you just get:
 Dir["File_server_full_20100702*"]
=> ["File_server_full_2010070200.7z", "File_server_full_2010070201.7z"]

If you want more control about what is matched you might think using e.g the creation time on the file to
see when the file was touched.
e.g
Dir["File_server_full_20100702*"].each { | file | puts File.ctime(file) }

You then can compare it e.g with the Date class facilities.

Regards
Friedrich


Andrew DoadesIT Manager

Author

Commented:
Thanks, this is exactly what I needed!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial