You are not logged in.
Pages: 1
I wrote a short routine in order to identify missing files in a backup... it works fine until it hits special characters in path or filenames. When this happens, substitution doesn't occur and the relative path is not created which leads to the file not being found.
:VerifyMissingFiles
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
)
call set Pathx=%%Pathx:!RootPath!=%% - this is the problem child
It removes !RootPath! with substitution - !RootPath! is D:\Users\Username in this case
leaving the relative path that get appended to %BackupLocation%\!UserID!\!MACx! resulting in the backup location to search. When this hits an & or other special character in a file or path name substitution doesn't occur - see below:
_____________resulting paths output:_________________
source (Pathx before substitution) D:\Users\UserA\Documents\BA 211\Quizzes\Ch 9 & 10 Liabilities - KEY.docx
root path D:\Users\UserA
relative path (Pathx after substitution) D:\Users\UserA\Documents\BA 211\Quizzes\Ch 9 & 10 Liabilities - KEY.docx
backup location full path "\\0.0.0.0\UserBackup\UserFiles\UserA\00-00-00-00-00-00D:\Users\UserA\Documents\BA 211\Quizzes\Ch 9 & 10 Liabilities - KEY.docx"
This file won't verify because path becomes invalid when substitution doesn't occur
When there is no & in the path, things go normally -
source (Pathx before substitution) D:\Users\UserA\Documents\BA 211\Quizzes\Final Exam - S11 Version A.docx
root path D:\Users\UserA
relative path (Pathx after substitution) \Documents\BA 211\Quizzes\Final Exam - S11 Version A.docx
backup location full path "\\0.0.0.0\UserBackup\UserFiles\UserA\00-00-00-00-00-00\Documents\BA 211\Quizzes\Final Exam - S11 Version A.docx"
this file verifies normally
_________________________
call set Pathx=%%Pathx:!RootPath!=%%
I'm not sure, but maybe delaying expansion of Pathx on the line of code above would fix this? I'd try it, but I don't know how... lol )
Any help is much appreciated, Thank you!
Offline
I was able to eliminate & as a problem in file names just by using quotes around the variable substitution:
call set Pathx="%%Pathx:!RootPath!=%%"
however, this didn't fix other special characters like ^
Offline
Trying to process special characters in CMD syntax is an uphill struggle.
I've typically used/misused "robocopy" in the past, for the sort of thing you are trying to do.
FYI If you can post your code using the code tags (rightmost button that looks like a console above the post editing box) it will make it much easier for people to read/understand your code and output.
Last edited by bluesxman (01 May 2020 13:50)
cmd | *sh | ruby | chef
Offline
Pages: 1