Hello everyone and thanks for your help!
I currently have this program that renames a single file to lowercase:
This file is Lowercase.bat
set LC1=%~nx1
set LC1=%LC1:"=%
set LC1=%LC1:A=a%
set LC1=%LC1:B=b%
set LC1=%LC1:C=c%
set LC1=%LC1:D=d%
set LC1=%LC1:E=e%
set LC1=%LC1:F=f%
set LC1=%LC1:G=g%
set LC1=%LC1:H=h%
set LC1=%LC1:I=i%
set LC1=%LC1:J=j%
set LC1=%LC1:K=k%
set LC1=%LC1:L=l%
set LC1=%LC1:M=m%
set LC1=%LC1:N=n%
set LC1=%LC1:O=o%
set LC1=%LC1:P=p%
set LC1=%LC1:Q=q%
set LC1=%LC1:R=r%
set LC1=%LC1:S=s%
set LC1=%LC1:T=t%
set LC1=%LC1:U=u%
set LC1=%LC1:V=v%
set LC1=%LC1:W=w%
set LC1=%LC1:X=x%
set LC1=%LC1:Y=y%
set LC1=%LC1:Z=z%
ren "%1" "%LC1%"
And I have this file that renames (supposively) every file and folder in every subfolder. It does it by calling the above batch multiple times
This is called LowerCaseRecursive.bat
pushd %1
dir *.* /b /a-d /s > lwrcase.log
for /f %%i in ('type lwrcase.log') do call LowerCase "%%i"
del /q lwrcase.log
popd
You call the program by using the command line and say LowerCaseRecursive.bat “C:\Test\”. Everything works fine but it does NOT rename files that include a
So everything works great, but it can’t seem to rename files with a space on them, even though it has the full name in lwrcase.log. The for just parses until the first space.
I’ve little knowledge of windows batch programming, any ideas?
Thanks a lot everyone! If you have any questions about this just ask me.
EDIT: The problem is most likely on the individuals calls to lowercase.bat. Debugging I can see that the call to lowercase.bat already has the entire filename after the space cropped. Meaning that if the file is C:\Hello\My File.txt it will call:
call Lowercase "C:\Hello\My"
You should read carefully the FOR help, accessed by typing
HELP FORorFOR /?from a command prompt. You will see that FOR /F parses each line into tokens, and the default token delimiters are space and tab.You simply need to disable the token parsing by setting DELIMS to nothing. Technically, you should also set EOL to some character that can never start a path. The default EOL character is
;. Any line that begins with;will be ignored, and;is valid in folder and file names (though very unusual). A path cannot begin with:, so that is a good choice.EDIT
Here are some unsolicited improvements to your code 🙂
Your Lowercase.bat can be made much smaller. This works because the search part of search and replace is case insensitive.
And your LowerCaseRecursive.bat can also be greatly simplified into a single line.