0

i have script bat file for move file from one folder to each other folder and create the log file. the script like this :

Copy /y c:\temp\temp1\* c:\temp\temp2\ >>c:\temp\makelog.txt
echo %Date% >>c:\temp\makelog.txt %Time% >>c:\temp\makelog.txt

and ouput log like this

c:\temp\temp1\test.jpg
    1 file(s) copied.
03-Nov-17  10:41:35.52

i hope i can create output like this :

c:\temp\temp1\test.jpg | 1 file(s) copied. | 03-Nov-17  10:41:35.52

any one help me?

thank you so much.

2
  • You would need to use a FOR /F command to capture the output of the COPY command. But you also have to take into consideration if it copies more than one file the output will be completely different. Commented Nov 3, 2017 at 3:58
  • where i must put a FOR /F code in my script? Commented Nov 3, 2017 at 4:14

1 Answer 1

1

As I said in my comment above, this is only going to work if you are copying a single file. If the wildcard finds more than one file then this code will not work.

This is how you can do it in one line from the cmd prompt.

cmd /V:ON /C "(FOR /F "Tokens=* delims= " %G IN ('Copy /y c:\temp\temp1\* c:\temp\temp2\') DO @((IF DEFINED LINE1 SET "LINE2=%G")&(IF NOT DEFINED LINE1 SET "LINE1=%G"))) &ECHO !LINE1! ^| !LINE2! ^| %date% %time%"

This is how you would do it from a batch file.

@echo off
FOR /F "Tokens=* delims= " %%G IN ('Copy /y c:\temp\temp1\* c:\temp\temp2\') DO (
    IF DEFINED LINE1 SET "LINE2=%%G"
    IF NOT DEFINED LINE1 SET "LINE1=%%G"
)
ECHO %LINE1% ^| %LINE2% ^| %date% %time%
pause
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.