Question

I have a folder on my local PC that is populated with an Excel report that is generated daily by Access. The Excel file name looks something like this: Report Data 130712.xlsx
With the date format YYMMDD

My requirement is to copy that Excel file, daily, to a network share drive. I have stared to write a batch file, but I am not sure how to increment the day. So when the batch job runs it will look for the file name with the current date and copy that file to the share folder.

Today's batch job

xcopy /s "c:\Report_Folder\Reports\Report Data 130712.xlsx U:\target\Reporting Data File

Tomorrow's batch job

xcopy /s "c:\Report_Folder\Reports\Report Data 130713.xlsx U:\target\Reporting Data File
Was it helpful?

Solution

Simple Locale Dependent Method

xcopy "c:\Report_Folder\Reports\Report Data %Date:~12,2%%Date:~4,2%%Date:~7,2%.xlsx" "U:\target\Reporting Data File\"

Locale Independent Method

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set datestamp=%dt:~2,6%
xcopy "c:\Report_Folder\Reports\Report Data %Datestamp%.xlsx" "U:\target\Reporting Data File\"

Options are to Parse these (see above)

wmic OS Get localdatetime

or

wmic Path Win32_LocalTime get /value
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top