I am trying to write a batch script that can find the files created/modified/newer since yesterday and/or any specific day from today in a particular folder. Then those files need to be copied to different location.

I tried to use the forfiles command but my XP doesn't have that command.

Any help would be awesome!

link|improve this question
1  
The utility forfiles is not included with Windows, it is from the Windows Server 2000 Resource Kit. You can also download the executable itself from the Petri site. – jscott Nov 3 '11 at 19:16
If you're willing to install cygwin, you can use find /cygdrive/c/your/folder -ctime 1 | xargs mv -t /cygdrive/c/new/folder to perform all that (files changed within the last 24 hours; there are other time options if you need to be more precise). – Kevin Nov 3 '11 at 20:01
hey kevin - thanks for this! even though i havent worked with cygwin and dont know what it is, i will give it a shot. – newbie Nov 3 '11 at 20:28
thank you scott! – newbie Nov 4 '11 at 14:26
If installing something as extensive as cygwin is a possibility, you should look into using powershell as well. – RobW Nov 4 '11 at 15:56
show 2 more comments
feedback

1 Answer

You can use Horst Schaeffer's excellent wasfile.exe tool:

for /r c:\particular_folder %i in (*.*) do @wasfile.exe %i created after Today-1 > nul && @copy %i f:\different_location

You can change created and modified per your need:

WasFile, ver. 2.2 (c) 2006-2007, Horst Schaeffer
compares ..
    the time&date of two files (or directories),
    the date only, time ignored
    the date of a file with TODAY-n (days)
    the time&date of a file with NOW-n (minutes)
Examples:
    WasFile this.zip created before that.zip
    WasFile this.zip modified after today-8
Syntax:
    WasFile File1 [Stamp] [not] before|after|sametime File2 [Stamp] [Option]
    WasFile File1 [Stamp] [not] before|after|sametime today-n [Option]
    WasFile File1 [Stamp] [not] before|after|sametime now-n
Stamp is either:
    created, modified (default) or accessed
    (by default second stamp = first stamp)
Options to compare date only, ignore time:
    /DateLocal or /DateUTC
    (if TODAY is used, default is /DateLocal)
Result by errorlevel:
    0: true, 1: false, 255: error (message to STDERR)

by the way when you put (.), does it mean look for any format/kind of the file? can i just put *.csv instead to search csv file only?

I think you mean (*.*)? Yes, this tells you what set you are interested in. *.csv would isolate just the csv files.

also why are you using @wasfile.exe, nul, @ copy and switch %i (two places)

You might benefit from reading some web sites for background:
http://www.netikka.net/tsneti/http/tsnetihttpprog.php#batch
http://www.netikka.net/tsneti/info/tscmd.php

Google batch tutorial for more sites.

In a batch file, @command means don't echo the command line to the screen. Otherwise, you will see both what you asked for as well as what the result was. The && means 'process what follows if command is successful' and determines this by errorlevel. If I wanted 'was not successful' I would have used ||.

In this case, you read the code as: Is the file newer than my target date, and if yes (&&) copy it to some location. Don't show me any output from my command ">nul"
Ok?

link|improve this answer
thank you very much rob! i will give it a shot. by the way when you put (.), does it mean look for any format/kind of the file? can i just put *.csv instead to search csv file only? also why are you using @wasfile.exe, nul, @ copy and switch %i (two places)? – newbie Nov 4 '11 at 16:45
I'll append my answer to my post above – RobW Nov 4 '11 at 19:33
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.