copy latest files from source to target directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
somu_june
Posts: 30
Joined: 19 Jun 2013 20:26

copy latest files from source to target directory

#1 Post by somu_june » 24 Jun 2013 14:09

Hi,

I'm trying to copy the latest .dsx files from source H:\Data\Dir\datastage\ to H:\Data\Dir\Current\. I tried using the below script and I'm getting an warning message

The system cannot find the file specified.

I know below script will try to copy all the .dsx files but I need to copy only the latest files

@echo off
cd\
set filepath=H:\Data\Dir
FOR /F "TOKENS=*" %%G IN ('DIR/B "%filepath%\datastage\*.dsx"') DO
copy %filepath%\datastage\*.%%f "%filepath%\Current"

Thanks,
Raju

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy latest files from source to target directory

#2 Post by foxidrive » 24 Jun 2013 17:05

somu_june wrote:I'm trying to copy the latest .dsx files from source H:\Data\Dir\datastage\ to H:\Data\Dir\Current\.
I know below script will try to copy all the .dsx files but I need to copy only the latest files


How many of the latest files? How many files are there in total?

Post Reply