• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

How do I write the output of a COPY command to a txt file from a BATCH file


Hi,

I am copying one directory to another directory and i want to make a log text file.

At the momment i have this:

:COPYMOVIESDIR
ECHO.
ECHO Copying original files from root/movies to online directory ...
COPY %MOVIESA% %MOVIESB%
IF errorlevel 1 GOTO ERRORCOPY
IF NOT ERRORLEVEL 1 GOTO START

------------------------- I know to write to a text file for example is:       echo example writing>>c:\LogFile.txt

But how do i combine this with COPY command to write the ouput to a file?
0
zoomzoomdevelopers
Asked:
zoomzoomdevelopers
1 Solution
 
nikkilockeCommented:
Hi zoomzoomdevelopers,

Just like your example.

COPY %MOVIESA% %MOVIESB% >>c:\LogFile.txt

Hope this helps,

Nikki
0
 
rushtoshankarCommented:
add one more line before the copy command.
ECHO  COPY %MOVIESA% %MOVIESB% > log

this will add the copy command and file names with path to that file
0
 
aravindtjCommented:
If the copy success, put these lines in that section
echo %MOVIESA% copied to %MOVIESB% - Success.
Similary, for files not copied,
echo %MOVIESA% copied to %MOVIESB% - Failure.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cmalakarCommented:
Hi,

U can use the same syntax as shown below..

@echo off

set FILE1=file1.c
set FILE2=file3.c

copy %FILE1% %FILE2% > file
0
 
InteractiveMindCommented:
If you wish to log all copied files, and there outcome (error or not), then you can do this:


@echo off
set origin=c:\originFolder
set destiny=c:\destinyFolder
set log=c:\log.txt
cd %origin%
echo Starting to copy content of %origin% to %destiny%>>%log%
echo.>>%log%
for /f "delims=" %%F in ('dir /s /b') do (
   echo Attempting to copy "%%F" to %destiny% . . .>>%log%
   copy "%%F" "%destiny%" >nul
   if %errorlevel% neq 0 (echo Failed [%errorlevel%]>>%log%) else (echo Successful [0]>>%log%)
)
echo.>>%log%
echo Complete>>%log%



Regards;
0
 
InteractiveMindCommented:
Actually, change this line:

   copy "%%F" "%destiny%" >nul

to:

   copy "%%F" "%destiny%" /y >nul
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now