Domanda

This is my initial batch script.

@echo off

if "%MACHINE%" == "0" ( call:verif TestFolder txt )
if "%MACHINE%" == "0" ( call:verif TestFolder exe )

goto:eof

:verif
if not exist %~1 ( mkdir %~1 )
move *.%~2 ..\..\%~1\

What I want to do, is log the file names that failed to move in log.txt

What I tried: robocopy ( supports logs but I'm not pleased because I want to log only the fails )

What I'm thinking would work is output stderr, something like:

move *.%~2 ..\..\%~1\ 2>stderr.txt

Outputs ( for a file with no rights )

Access is denied.

But how will I know for which .exe or .txt the error is? Needs to concatenate somehow with the file name.

Please let me know if you know a solution or a better way.

È stato utile?

Soluzione

Instead of moving all *.txt and .exe files at the same time - why not use a for loop to move them individually?

for %%a in (*.%~2) do move %%a ..\..\%~1\ || echo %%a>>fail.log

The code after || will only run if an error level is set by the move command.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top