Folder:
C:\My Files
Example list of files:
Mr. Apple.removethis.txt My.apples.are.rotten.removethis.txt ThisAppleIsBad.removethis.doc I Like Apple Pie because apples are great.(Awesome even).removethis.pdf ...
Obviously (by my examples), I want to remove .removethis from all of the file names.
Simple, right?
RENAME (like most DOS) gets confused with spaces in files and folders.
RENAME gets lost with the use of periods.
I can usually work around these issues, but for some reason everything I try causes different things to happen to different files, and every work-around I come up with falls flat somewhere.
I won't even try listing them, except my latest attempt.
BTW... I've manipulated where my quotes are... pretty much everywhere, and this is my best result.
I just know that I'm missing something really simple... but this whole mission was supposed to be simple.
BAT:
for %%i in (*.txt) do ( set MyFile=%%i rename "%MyFile%" "%MyFile:~0, -11%.txt" )
Results in:
Quote
C:\My Files>z-MyBatchFile.bat
C:\My Files>for %i in (*.txt) do (
set MyFile=%i
rename "" "~0, -11.txt"
)
C:\My Files>(
set MyFile=Mr. Apple.removethis.txt
rename "" "~0, -11.txt"
)
The system cannot find the file specified.
C:\My Files>(
set MyFile=My.apples.are.rotten.removethis.txt
rename "" "~0, -11.txt"
)
The system cannot find the file specified.
C:\My Files>
C:\My Files>for %i in (*.txt) do (
set MyFile=%i
rename "" "~0, -11.txt"
)
C:\My Files>(
set MyFile=Mr. Apple.removethis.txt
rename "" "~0, -11.txt"
)
The system cannot find the file specified.
C:\My Files>(
set MyFile=My.apples.are.rotten.removethis.txt
rename "" "~0, -11.txt"
)
The system cannot find the file specified.
C:\My Files>



Help
Back to top









