1.

Solve : xcopy certain dates or certain folders help.?

Answer»

Hi I'm pretty new to batch files so here goes,
I'm looking to xcopy certain log files but exclude others from being copied,
for eg the log files are named by date 200909026 through to 200400101. so i want to xcopy only from 20040101 to 20090901 and leave the rest.
Could some one point me to the correct syntax please.
Thanksyou.

@echo off
Set mindate=20040101
Set maxdate=20090901
For /F "tokens=1,2 delims=." %%a in ('dir /b *.log') do if not "%%a" LSS "%mindate%" if not "%%a" gtr "%maxdate%" copy %%a.%%b TARGETLOCATION

That should do it. It's not tested though. Thank for your response helpmeh,
could you explanin some of the syntax pls so i have a better understanding in the futureI have another question i wrote this simple batch file:

start /d "C:\program Files\test" packer.exe

start /wait/b XCOPY "C:\program files\Archived Logs" "D:\Archived logs" /E /V /C /I /Q /H /K /O /X /Y

basically whats mean to happen is packer.exe program zipps up a log file then creates a folder called and C:\program files\Archived Logs and inserts it in there which works ok but then when this is finished i want to copy the latest zipped file from the archived folder to D:\Archived logs , the xcopy part is not working. But does work if i run the batch file twice,i think the batch file needs to wait until packer.exe completes ,
What am i doing wrong ?
Thanks

sorry should be

tart /d "C:\program Files\test" packer.exe

start /wait/b XCOPY "C:\program files\Archived Logs\"*" "D:\Archived logs" /E /V /C /I /Q /H /K /O /X /Y

Still working though ,
Quote from: jamster69 on September 27, 2009, 10:12:55 AM

Thank for your response helpmeh,
could you explanin some of the syntax pls so i have a better understanding in the future
Well, the set command should be fairly obvious to you. But here's how the for loop works.

for /f
The command with the /f switch. See FOR /? for more information on other switches.

"tokens=1,2
Part one of the options. Specifies that the first 2 tokens are used. By default is 1.

delims=."
Part 2 of the options. It tells the command where to divide the output (see later) by for each token. Must be used last. By default is a space and/or a tab.

%%a
Specifies the first for variable (or the only one in some cases).

in
(self-explanitory)

('dir /b *.log')
Collects the output from that command (see DIR /? for more INFO on that command).

do
(self-explanitory)

If not "%%a" LSS "%mindate%"
If the value of %%a is not less than the value of %mindate% do:

If not "%%a" gtr "%maxdate%"
If the value of %%a is not greater than the value of %maxdate% do:

Copy %%a.%%b TARGETLOCATION
Copy the value of %%a.%%b (which is the file's name .log ex 20090801.log) to the target LOCATION (TARGETLOCATION), which you had to specify.

If you need any more help, feel FREE to ask.


Discussion

No Comment Found