This should be simple not sure why it isn't working... I have a batch file with 2 cmds and am trying to get it to write the output to a log file.
Here is what is in my batch file:
PUSHD "\\My Very Long\Exact Directory\" >>logfile.txt
for /f "skip=7 eol=: delims=" %%F in ('dir /b /o-d *.xlsm') do del "%%F" >>logfile.txt
The PUSHD is because this file is in on a remote file storage \\My Very Long\Exact Directory\
and I want the actions to be taken within the directory where the batch file is, and not the directory that it is being called from. The second command cleans up the directory by deleting old copies.
When I run the batch, by either calling it from the remote server, or by double clicking it straight away, the cmd window opens and runs the clean up. It will create a file in the directory called 'logfile.txt' but it is empty.
The process that calls this batch file from the remote server is scheduled, and I want to see what happened when this was called later. How do I get the results to write to the log file. I imagine it should look very similar (it not the same) as what the cmd window pops opens and shows.
I reference this other post: Redirecting Output from within Batch file
Adding more as I have been informed PUSHD nor DEL have outputs... I put a pause in the file to capture the cmd window. I am looking to capture this information and of course any errors that occur. Maybe this is the wrong approach?
X:\File Path\BackUps>PUSHD "\\My Very Long\Exact Directory\" 1>>logfile.txt
Y:\File Path\BackUps>for /F "skip=7 eol=: delims=" %F in ('dir /b /o-d *.xlsm') do del "%F" 1>>logfile.txt
Y:\File Path\BackUps>del "2015 CSLD Weekly Comment Analysis 2015-10-10 9_11_09 .xlsm" 1>>logfile.txt
Y:\File Path\BackUps>del "2015 CSLD Weekly Comment Analysis 2015-10-10 23_55_29 .xlsm" 1>>logfile.txt
Y:\File Path\BackUps>pause
Press any key to continue . . .