I'm making a simple *bat file with drag/drop ability for replacing white spaces( ) and dots(.) for underscores(_).
I think this should work, but it doesn't:
@ECHO OFF
setlocal enabledelayedexpansion
FOR %%f IN (%*) DO (
set filename=%%~nj
set filename=!filename:.=_!
set filename=!filename: =_!
if not "!filename!"=="%%~nf" RENAME "%%f" "!filename!%%~xf"
)
Do you know what is going on?
Your loop variable is
%%f
but in the first line, where you assign it tofilename
you use%%j
.Your code should look like this:
Also, you might want to make sure you strip eventual quotes consistently. That is, the last line of your loop should read:
Then, you should not suppress the directory-part of the files being moved.
Before letting your code loose, you may want to replace that last line with something like:
Then, after your drag n' drop operation inspect "%TEMP%\test.txt" to see if it contains the operations, and on the files, you expected.
For reference, here is the complete file after all changes:
try this:
Put the assignment of
set
in double quotes to protect your code from ugly characters. Setdelayed expansion
later in the for loop to save exclamation marks and carets in file names.