I have multiple folders containing assets (each folder has subfolders containing these assets .mp3, .txt, .png, etc). I want to copy all this assets along with the subfolder to a single location/folder. I was able to successfully run a robocopy command to achieve copying of assets along with subfolders from one folder to another folder:
robocopy source target /s
I will be running a scheduler once daily to copy the assets. Also I wanted to store the name of all the copied assets in a log file. The name of the log file should be in the form of
log_currentDate.txt
for example if the today's date is 20th Oct 2015… the name of the log file should be:
log_20151020.txt
The next day i.e. 21st Oct 2015, it should be:
log_20151021.txt
This log file should contain the name of all the copied assets on 20th Oct 2015, 21st Oct 2015 and so on. I created a batch command (thanks to @DavidPostill) to create a log as follows:
@echo off
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (
set _date=%%a%%b%%c
)
echo robocopy source target /log:D:\ABC\log%_date%.txt
This creates a log with the name "logTue2010.txt" (i.e. logdayddmm format). Problem:
- Where does this log file gets stored? To make visible this log file, I have to write a separate command everyday as follows:
robocopy source target /log:D:\ABC\logWed1021.txt /tee /s
- How do I ensure that a separate copy of log is obtained each day?
- Also with the current command, the log file contains the entire output displayed on the cmd window. I just want it to contain the name of the asset with its extension.
EDIT: As per @JosefZ I edited my batch file as follows:
@echo off
for /f "tokens=2 delims==" %%G in ('wmic OS get LocalDateTime /value') do set "_date=%%G"
set "_date="%_date:~0,8%
echo robocopy source target /log:D:\ABC\log\log_%_date%.txt
robocopy source target /log:D:\ABC\log\log_%_date%.txt /S
I received the following output:
D:\ABC>D:\ABC\copy1.bat
robocopy source target /log:D:\ABC\log\log_.txt
Log File : D:\ABC\log\log_.txt
Best Answer
Get
YYYYMMDD
-formatted date independently of locale and regional settings usingfor /F
loop againstwmic
(Windows Management Instrumentation Command) and environment variable substring:There are more
robocopy
logging options:Above command (note
/NP /NDL /NJH /NJS /NS /NC
switches) will suppress almost all except (full-qualified) file names inrobocopy
output. However, file names are indented with some Tab and Space characters. Next code snippet should make output as desired:For
>
explanation, see redirection. And the log file gets stored in specified folder (D:\ABC\log\
); to ensure this, try