0

I am copying and renaming files as below.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET LOGFILE=file_transfer.log
call :Logit>>%LOGFILE% 2>&1
:Logit
echo Start time is: %date% %TIME%
set NEWFOLDER=new_folder
md "%NEWFOLDER%"
for /f "usebackq tokens=1,*" %%a in ("filelist.txt") do copy "%%a" ".\%NEWFOLDER%\%%b"
echo End time is: %date% %TIME%
:eof

When execute above script, I am getting log file as:

1 file(s) copied.
1 file(s) copied.
1 file(s) copied.

I need to get output in log file as:

1 file(s) copied - abc.jpg.
1 file(s) copied - xyz.jpg.
1 file(s) copied - 123.jpg.

How can I achieve this?

Bishan
  • 15,211
  • 52
  • 164
  • 258
  • What is appearing now is the stdout of the `COPY` command. To get the desired result will require an `ECHO` command be added in the body of the `FOR` loop. – lit Oct 19 '17 at 12:03
  • 1
    There is no need to make a CALL to the :Logit label. But if you are going to do that then you need a `GOTO :EOF` after your `CALL` command. And don't ever create the LABEL `:EOF` in your code. It is not needed. The `:EOF` label is predefined label that will always exits the current subroutine or batch program. – Squashman Oct 19 '17 at 14:23
  • `xcopy` returns the copied files too before the summary line; the disadvantage is the nasty [`F`ile/`D`irectory prompt](https://stackoverflow.com/a/33770152) when you specify a single source file, you specify the destination file rather than its parent folder only (by an appended `\ `) and the destination file does not yet exist; if the source file name is kept, you could do: `xcopy "D:\source\file.ext" "D:\destination\"`... – aschipfl Oct 19 '17 at 17:14

0 Answers0