Computer Hope

Microsoft => Microsoft Windows => Windows XP => Topic started by: oba_shonowo on April 02, 2008, 03:30:34 AM

Title: Copying files created today and deleting old files
Post by: oba_shonowo on April 02, 2008, 03:30:34 AM
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.
Title: Re: Copying files created today and deleting old files
Post by: Spoiler on April 02, 2008, 07:46:48 AM
How about a Batch file?

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

Title: Re: Copying files created today and deleting old files
Post by: oba_shonowo on April 03, 2008, 01:52:18 AM
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.
Title: Re: Copying files created today and deleting old files
Post by: Sidewinder on April 03, 2008, 05:15:41 AM
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

 8)
Title: Re: Copying files created today and deleting old files
Post by: oba_shonowo on April 18, 2008, 06:09:51 AM
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.