String manipulation is very awkward in the command prompt. Removing the contents of
%1 from the beginning of
%G would involve counting the characters of
%1 (loop through the characters and increase a counter by one) and then use the substring syntax (
Using forfiles should be much simpler, since it has a built-in command variable to access the relative path of the file (
This should work:
forfiles /S /P %1 /C "cmd /V:on /C if @isdir==FALSE set R=@relpath&set R=!R:~3,-1!&%~dp0rdiff signature @path | %~dp07za a -mx0 -si\"!R!\" %~dp0signatures.7z"
/S makes forfiles recursive.
/P %1 specifies the path.
/C "cmd /V:on /C ... executes
... in a subshell with delayed variable expansion (
if @isdir==FALSE checks for the presence of a file (rather than a directory).
set R=@relpath stores the relative path in a variable called
set R=!R:~3,-1! removes the string at the beginning
"\." and the trailing double-quote.
%~dp0 forfiles changes directories to execute the command, specifying
%~dp0 gives you the absolute path the batch file was run from.