views:

214

answers:

3

I need to make a batch file that can copy files from one path to another based on parameters.

For example, typing "datecopy -m 8 c:/copyfrom/*.* d:/copyto/*.*", would find all files in c:/copyfrom dated less than 8 months old, and copy them to d:/copyto -folder. Alternately, instead of -m for month, I could use -h for hour or -y for year.

That's not the full program of course, but should get me started. Thanks for any potential tips. :)

+1  A: 

I know this might not look like it's answering your question, but save yourself more pain and heartache than you can imagine by doing this in jscript or VbScript

Lately I've been looking at Windows Powershell, basically Windows Scripting on speed.
However you can be assured that Windows Script Host (jscript & VBScript) is already on Windows from XP onwards (possibly from W2k onwards).

My advice is to NOT use windows batch commands.

Binary Worrier
Powershell is a great way to go if you have it installed
RobS
Starting with Windows 98, even.
Joey
Tried to get it for Vista a month or two back, but there were some complications. Might try again with Win 7. Thanks for the reply btw, this is definitely an option, though I still need to find out about basic batch file scripting sooner or later as well.
Kahn
A: 

Supposing you can assemble a set of good-old-unix tools, do take a look at the find utility. It has the options you ask for, and more.

find c:/copy/from -atime 240 | xargs cp "{}" c:/copyto
xtofl
A: 

Here is a script that will copy files newer than 8 months.

# Script TimedCopy.txt
var str from, to, timediff, list, file
lf -n "*" $from ($ftype=="f") AND ($fmtime > addtime(diff(("-"+$timediff)))) > $list
while ($list <> "")
do
    lex "1" $list > $file
    system copy ("\""+$file+"\"") ("\""+$to+"\"")
done

The lf (list files) command is pretty flexible. Its help page is at http://www.biterscripting.com/helppages/lf.html .

To run the script, copy and paste the script into file C:/Scripts/TimedCopy.txt, start biterscripting and run this command.

script "C:/Scripts/TimedCopy.txt" from("c:/copyfrom") to("d:/copyto") timediff("240000000")

Explanation of the timediff argument

"240000000" means 240 days, 00 hours, 00 mins, 00 secs

"120000" means 12 hours, 00 mins, 00 secs

"3000" means 30 mins, 00 secs

"30" means 30 seconds

etc.

(By dated, I assume you mean modified. If you meant created, use $fctime instead of $fmtime in the script.)

Hope this helps.

P M
Wow, thanks. I'll check on this as soon as I'm able. :)
Kahn