1.

Solve : Copying files created today and deleting old files?

Answer»

Hello all. I am trying to use a command to copy a file that is created daily, move it to a folder on another machine and delete all the old versions of that file on the second machine.

Can anyone give me some guidiance on how it can be done on a Windows 2003 box.How about a Batch file?

DEL \\machine\share\old*.txt
Copy C:\path \\machine\share\file.txt

This is what I currently have:

copy F:\sqldata\MSSQL\BACKUP\master\*.BAK "\\172.25.32.6\d$\FEP\FEP Script Backup\master"
pause

I use * because I don't know how to pick then one for the current day. The other problem is I need to delete all the old ones in "\\172.25.32.6\d$\FEP\FEP Script Backup\master".

Pls HELP.Batch code does not do date ARITHMETIC very well. If the file to be copied has the most recent date, this little piece of doggerel should help:

Code: [Select]@echo off
del "\\172.25.32.6\d$\FEP\FEP Script Backup\master\*.*"
for /f "tokens=* delims=" %%v in ('dir /o:-d /s /b F:\sqldata\MSSQL\BACKUP\master\*.BAK') do (
copy %%v "\\172.25.32.6\d$\FEP\FEP Script Backup\master"
goto end
)
:end


Thanks. It worked. I used skip to replace the go to label. I ALSO reversed the list given by the dir command to do the correct delete.



Discussion

No Comment Found