A BAT file becomes easier to monitor when it writes a log. The log records output from the process and can help you investigate what happened.
The original example below creates a variable containing the log file's path and name. Its final command moves files. Read every command first, back up important data and use disposable test folders. The paths and variable names are preserved from the Spanish article; do not run them against real files without adapting and checking them.
Set the log path
Add this line to the BAT file:
SET LogNombre=C:\LogArchivo.log
The example writes to the root of drive C. Check that your chosen log location exists and is writable before testing.
Add a separator
A separator helps distinguish one run from the next. The original guide uses a line of hyphens:
ECHO -------------------------------------------------- >> %LogNombre%
Record the date and time
date /t >> %LogNombre%
time /t >> %LogNombre%
The complete original example
This example moves files from C:\Prueba1 to C:\Prueba2 and appends the displayed MOVE output to the log:
SET LogNombre=C:\LogArchivo.log
ECHO -------------------------------------------------- >> %LogNombre%
date /t >> %LogNombre%
time /t >> %LogNombre%
MOVE C:\Prueba1\*.* C:\Prueba2 >> %LogNombre%
Output shown in the original article
--------------------------------------------------
16-Dec-20
11:51 AM
C:\Prueba1\Archivo1.txt
C:\Prueba1\Archivo2.txt
C:\Prueba1\Archivo3.txt
3 file(s) moved.
The date, time and file names above belong to the original example. They are not the result of a new execution performed for this translation. This is a basic logging demonstration, not a complete error-handling script.
Comments (0)
Comments are shown in their original language.
No comments have been published yet. Be the first to join the conversation.