How do I create a log of robocopy actions and save in a text file named with today's date?

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:

Robocopy

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 /tee option

    Writes 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 echo if you are happy with the date format
  • Use /s if your source directory contains subdirectories that need copying.

Syntax

robocopy <Source> <Destination> [<File>[ ...]] [<Options>]

...

Logging options

...

enter image description here

Source Robocopy

4

This 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like