I am trying to copy files recursively
and then rename them according their containg folder name.
I am trying to extract folder name from path.
So far I got this but id does not work:
SET "MyPath=C:\MyFolder\"
SETLOCAL EnableDelayedExpansion
FOR /R "%MyPath%" %%F DO (
ECHO "%%~pF" :: ~pF expands F to a path only
:: this is in my case a variable (length of a file that comes froma function call)
SET /a intFileLength=5
SET strPathOnly=%%~pF
SET folderName=!strPathOnly:~-intFileLength!
ECHO "Extracted folder name: " !folderName!
)
endlocal
This is my echo
Extracted folder name: " strPathOnly:~-intFileLength
SET /a intFileLength = 5
:: The following works
SET folderName=!strPathOnly:~-5!
:: This one does not work
SET folderName=!strPathOnly:~-intFileLength!