You are not logged in.

#1 29 Apr 2020 23:58

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Parser Puzzle

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 smile)

Any help is much appreciated, Thank you!

Offline

#2 30 Apr 2020 18:56

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Re: Parser Puzzle

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

#3 01 May 2020 13:48

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: Parser Puzzle

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

Board footer

Powered by