简体   繁体   中英

Batch file to copy a file based on date modified

Folder : C:\\data\\PRODDB\\dir

In the above folder files get created daily in the morning .I want to create a batch script which checks/identifies that folder for the latest file based on date and copy to other location ( d:\\test).

eg: file created as backup_110513.DMP 11/05/2013

We will use a backup software to schedule a backup job to backup the files in the folder(d:\\test) and after that particular file gets backed up from d:\\folder, need to create another script which empties the folder d:\\test.

Thanks.

这将复制部分文件,修改日期为今天

forfiles /P "c:\data\PRODDB\dir" /M *.DMP /D +0 /C "cmd /c copy @path d:\test"

Try this. When the results you want are displayed remove the "echo.". The goto is necessary so that we exit the loop immediately after copying the newest file.

@echo off
for /f "delims=" %%a in ('dir C:\data\PRODDB\dir /B /A-D /O-D') do echo.copy "%%a" d:\test & goto :Done
:Done
pause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM