I am copying some assets from one folder to another using robocopy in command prompt. However, I want to log name of all those copied assets in a .txt file. This .txt file should be saved in the form of "currentDate.txt".
Actual Scenario: We are going to run a scheduler once daily. This scheduler will copy all the assets from one folder to another.
Refer below link for a screenshot of Robocopy Command:
Any help will be highly appreciated :-)
3 Answers
I want to log name of all those copied assets in a .txt file.
This .txt file should be saved in the form of "currentDate.txt".
Use the robocopy
/log:<LogFile>option.You might also want to use the
/teeoptionWrites the status output to the console window, as well as to the log file.
Example batch file (copyassets.cmd):
@echo off
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do ( set _date=%%a%%b%%c )
echo robocopy ship shore /log:%_date%.txt- Modify as you like to get your prefered date format.
- Remove the last
echoif you are happy with the date format - Use
/sif your source directory contains subdirectories that need copying.
Syntax
robocopy <Source> <Destination> [<File>[ ...]] [<Options>]...
Logging options
...
Source Robocopy
4This is a solution to create a different log file every day. You can just call robocopy in PowerShell or batch command file and do your file manipulation and have it create the log, then rename the log file on the next line. The example:
Rename-Item -Path "C:\logs\robocopy.log" -NewName "robocopy-$(Get-Date -F yyyy.MM.dd)$($_.Extension).log"The result will be a dated file like this:
robocopy-2021.06.22.log
The log of RoboCopy is in DOS format which isn't really good.. Try GS RichCopy - has got all the features of RoboCopy, but it has some more features like copying open/locked files, can copy the timestamps, and has a GUI interface with a nice looking log which you can easily copy and paste in a notepad.
1