You are not logged in.
Pages: 1
Hi All, I've got a puzzler:
for /R D:\Users\UserX\Contacts\ %%A in (*.*) do if not exist !BackupLocation!\!UserID!\!MACx!\Contacts\%%~nxA echo %%~A >> !WorkingDirectory!\missingFiles.txt
The above works fine and creates a text file that lists files in the source directory that are not in the backup directory.
However this does not work:
for /R !UserFolder!\!UserID!\Contacts\ %%A in (*.*) do if not exist !BackupLocation!\!UserID!\!MACx!\Contacts\%%~nxA echo %%~A >> !WorkingDirectory!\missingFiles.txt
in this case !UserFolder!=D:\Users and !UserID!=UserX so I figured it would work... but apparently you can't use a variable before the parameter in a for /R loop?
How can I do this?
Offline
You can use dir to walk the directory instead and parse that output.
for /f "delims=" %%A in ('dir /S /b !UserFolder!\!UserID!\Contacts\') do if not exist !BackupLocation!\!UserID!\!MACx!\Contacts\%%~nxA echo %%~A >> !WorkingDirectory!\missingFiles.txt
Offline
Very cool... Thank you Shadow Thief!
Offline
Well... almost. Fails when it gets to subdirectories because %%~nxA doesn't contain the path below the root folder... not sure what to do.
Offline
The answer was a little substitution to remove the root portion of the source path to create a relative path that could be appended to the backup location and searched, but this led to another problem... see post "Parser Puzzler"
for /f "delims=" %%A in ('If Exist "!RootPath!\!folder!" dir /S /b "!RootPath!\!folder!"') do (
Set Pathx=%%A
call set Pathx=%%Pathx:!RootPath!=%%
if not exist "%BackupLocation%\!UserID!\!MACx!!Pathx!" echo %%~A >> %WorkingDirectory%\missingFiles.txt
)
Offline
Pages: 1