0

I need help to create a batch file to copy files with specifc date and version. And my date will be as of yesterday. Example file name:- abcde-20150811-v1.csv

I have tried xcopy with /d:08-11-2015 ( it picks all files with date modified as 08-11-2015 MM-DD-YYYY)

Is there a way that my batch automatically picks the date and gets changed everyday.

2
  • I don't understand your question. Do you mean copy files that has file name contains yesterday's date? Or simply copy yesterday modified files?
    – Happy Face
    Aug 11, 2015 at 17:29
  • Copy files that has filename containing yesterdays date
    – aditya v
    Aug 11, 2015 at 17:55

2 Answers 2

0

You might take a look at this: How to get and display yesterday date?

If I were you, I'd go with a scripting language like Perl, or use PowerShell.

0

Try this piece of code, haven't tried it yet though.

@echo off

set completepath=c:\users\microsoft\desktop\source
set destination=c:\users\microsoft\desktop\destination

set /a yesterday=%date:~4,2% - 1
set yesterday_date=%date:~10,2%%date:~7,2%%yesterday%

FOR /R %completepath% %%G IN (*.csv) DO call :process "%%~dpG" "%%~nG"
pause >nul

:process
SET %name%=%~2
SET chkname=%name:*%yesterday_date%=?%
IF "%chkname:~0,1%"=="?" (
    xcopy %~1 %destination% /y 
)

You may change the completepath and the destination variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.