0

I have a bunch of Excel Workbooks that update periodically. I want to copy these files every Sunday to the folder created with current date in the name (e.g. Workbooks-28.06.2017). I have written a batch script but it is not working.

What am I doing wrong?

Code:

@echo OFF

xcopy /s C:\Users\rerraboina\Desktop\tracker automation\Consolidation\test dynamic

for /f "skip=1" %%d in ('wmic os get localdatetime') do if not defined mydate set mydate=%%d
md %mydate:~0,8%
3
  • You should enclose the paths with spaces in double quotations. Commented Jun 28, 2017 at 7:24
  • @Azeem thank you, it is creating only folder with the date but it is not copying the files from source folder to the date folder. Please help Commented Jun 28, 2017 at 7:30
  • You are welcome! You have to accept the edit to show it. BTW, you are xcopying before creating the folder and the second parameter destination is missing e.g. xcopy source destination. I've posted my answer. You can go through it and then compare it with yours to understand what is happening here. Commented Jun 28, 2017 at 7:41

1 Answer 1

1

Here's an example:

archive.bat

@ ECHO OFF

PUSHD %~dp0

FOR /f "skip=1" %%d IN ('WMIC OS get LocalDateTime') DO IF NOT DEFINED myDate SET myDate=%%d
SET archiveDirName=Workbooks-%myDate:~0,8%
MD %archiveDirName%

XCOPY /S /I /Y "Excel Workbooks" %archiveDirName%\

POPD

"Excel Workbooks" is an example folder which contains multiple subfolders having on *.xlsx file in each.

Sign up to request clarification or add additional context in comments.

8 Comments

It created only folder as "Workbooks-2017062" but files are not transferred. I have tried with and without replacing "Excel Workbooks" with my path, but its not working.
@AayushmanR: Actually, that was an example. I've used Excel Workbooks in my code. You have to put the folder name with full path in quotations. If that doesn't work, then post your code here with error.
@ ECHO OFF FOR /f "skip=1" %%d IN ('WMIC OS get LocalDateTime') DO IF NOT DEFINED mydate set mydate=%%d md %mydate:~0,8% SET archiveDirName="Workbooks-%myDate:~0,8%" MD %archiveDirName% XCOPY /s "C:\Users\rerraboina\Desktop\tracker automation\Production Launches Cosolidation 2 june" %archiveDirName%
I have posted the code in the above comment. The only error is that it is creating the folder with current date but the files are transferring from source path to the created date fodler.
@AayushmanR: Yes. It copies the files from all the sources to the newly created folder. Do you want to copy each file along with its own folder?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.