Code: Select all
setlocal enabledelayedexpansion
for /D %%f in (*) do (
set /p str=< %%f\filename.txt
set str=!str:^|=!
echo.!str!
rename "%%f" "!str!")
pause
This works in most cases, but there's a problem when the original folder name has an exclamation mark in it. When this happens, it returns:
Code: Select all
The system cannot find the path specified
|= (or whatever str was last successfully set to)
The syntax of the command is incorrect
When I echo %%f, it outputs the directory with the exclamation marks removed. I think it's a problem related to enabledelayedexpansion, but I don't know how to perform this operation without it. Is there a way to remove exclamation marks from a list of folders?
There's also a problem when the first line of the .txt file contains an asterisk, I tried using
Code: Select all
set str=!str:*=!
but it doesn't work like it did with the vertical bar