0

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:

  1. 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

  1. How do I ensure that a separate copy of log is obtained each day?
  2. 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 1: With the following batch command I was able to resolve the issue pertaining to log filename format:

@ECHO OFF
for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
ECHO %ts:~0,8%_%ts:~8,4%
echo robocopy ship shore /log:D:\HAL\log\log_%ts:~0,8%_%ts:~8,4%.txt
robocopy Ship Shore /log:D:\HAL\log\log_%ts:~0,8%_%ts:~8,4%.txt /S

Also this batch command worked as well:

@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 ship shore /log:D:\HAL\log\log_%_date%.txt
robocopy ship shore /log:D:\HAL\log\log_%_date%.txt /S

However other questions asked here is still unanswered.

1

Please don't cross-ask StackExchange the same question. Answered already at https://serverfault.com/q/730450/257436 as follows:


Get YYYYMMDD-formatted date independently of locale and regional settings using for /F loop against wmic (Windows Management Instrumentation Command) and environment variable substring:

@echo off
for /f "tokens=2 delims==" %%G in ('wmic OS get LocalDateTime /value') do set "_date=%%G"
set "_date=%_date:~0,8%"

There are more robocopy logging options:

            /L : List only - don’t copy, timestamp or delete any files.
           /NP : No Progress - don’t display % copied.
      /unicode : Display the status output as Unicode text.   #
     /LOG:file : Output status to LOG file (overwrite existing log).
  /UNILOG:file : Output status to Unicode Log file (overwrite)
    /LOG+:file : Output status to LOG file (append to existing log).
 /UNILOG+:file : Output status to Unicode Log file (append)
           /TS : Include Source file Time Stamps in the output.
           /FP : Include Full Pathname of files in the output.
           /NS : No Size - don’t log file sizes.
           /NC : No Class - don’t log file classes.
          /NFL : No File List - don’t log file names.
          /NDL : No Directory List - don’t log directory names.
          /TEE : Output to console window, as well as the log file.
          /NJH : No Job Header.
          /NJS : No Job Summary.
1

Where does this log file gets stored? To make visible this log file I have to write a separate command everyday

That because you didn't remove the last echo or add /s in the batch file.

I explained this yesterday, during our lengthy chat.

I also updated my answer to inform you what you need to do:

  • Remove the last echo if you are happy with the date format
  • Use /s if your source directory contains subdirectories that need copying.

Here is the batch file with those changes:

@echo off
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (
set _date=%%a%%b%%c
)
robocopy ship shore /log:%_date%.txt /s

I also said in the chat:

You also need to change the batch file to get the correct date format for your locale.

What is the output of date /t from a command prompt on your PC?

I asked this because I could see the batch file had the wrong date format on your PC (but was correct on mine). I never go a response to this question (so the date format remained unfixed).

As JosefZ rightly points out in his answer a better way to get the date format you want (log_ddmmyy.txt) regardless of your locale is to use wmic.

With those changes as well the final batch file becomes:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims==" %%G in ('wmic OS get LocalDateTime /value') do (
  set _date=%%G
  set _date=!_date:~0,8!
  )
robocopy ship shore /log:D:\HAL\log_!_date!.txt /s
endlocal

Now the last step for you is to modify the log file format as you wish to contain the name of the asset with its extension:

  • Use the switches described in JosefZ's answer to do this.

  • Experiment with the switches to get the exact format you want. Hint: I think you need to use several of those switches.

  • Time format issue is resolved... I want other issues to be resolved like my current log file contains the entire summary that is thrown up in cmd by using /tee... i just want to log the name of the assets copied/moved... then how to fetch assets from multiple folders in different location to a single folder – Yash Saraiya Oct 21 '15 at 9:06
  • You need to start learning to this for yourself. The last part of my answer tells you what to do to change the log format. Please experiment and change it until you get the format you want. – DavidPostill Oct 21 '15 at 9:12
  • I already got the format I want... check edit to my question – Yash Saraiya Oct 21 '15 at 9:13
  • You don't need the /tee **in the batch file. We put that in yesterday so I could figure out what was wrong with what you where doing (which was getting no logfile because you didn't say in your question you had subdirectories and needed /s. – DavidPostill Oct 21 '15 at 9:14
  • Sigh. I not talking about the date format. When I say log format I mean the contents of the logfile. See the switches in the other answer. For example /NJH /NJS. You probably need to add those the the robocopy command to remove the job header and summary. – DavidPostill Oct 21 '15 at 9:18
0

So in order for RoboCopy to only include File file names is to add /NDL /NC /NS /NJH /NJS.

I have used this a lot.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.