1.

Solve : Batch file creating other file?

Answer»

I need to create batch file that copies files from one network folder to ANOTHER one. The syntax is:

[size=10]xcopy \\comp1\Folder\*.* \\comp2\Folder\*.* /D /Y[/size]
...so the files are updated if they are older in destination folder. I would like to add some code that creates short timedate.txt containing information about time and date of operation. Is it POSSIBLE?
It would look like:
[size=10]"edit file timedate.txt"
"write current time and date as text"
"close timedate.txt file"[/size]
So there would be some information when was the last copy done.
It would be great to give error information to timedate.txt if copying failed for some reason (doesn't matter what).
Maybe it's easier to learn and write VB program. MS-DOS batch files are a crud, but still sufficient for that To write current time and date to a file use

Code: [Select]echo Last edit at %DATE%, %TIME% >> timedate.txt

The return code of a command like xcopy is stored in an environment variable called ERRORLEVEL. If xcopy failed, the return value should be unequal ZERO, otherwise zero (WITHOUT guaranty, I didn't check). You can evaluate ERRORLEVEL with a code sequence like

Code: [Select]xcopy \\comp1\Folder\*.* \\comp2\Folder\*.* /D /Y
if %ERRORLEVEL% neq 0 echo xcopy failed >> timedate.txt

Cheers,
[glb]cs[/glb]*censored*.
Batch files are so simple and useful if you know how to use it!!!!
I want to learn more!!!
Could you recommand me some web pages about it?
This one is not enough.
I don't want to waste your time in a future.
Thank you for your help!! You are great.How to add info about number of files which were copied?
I could find it myself if I knew where :-/need to add information in timedate.txt about number of files that were copied....
...if I knew where to look for this information I wouldn't ask these basic questions http://www.chebucto.ns.ca/~ak621/DOS/Bat-Adv.html
I found something for myself



Discussion

No Comment Found