1.

Solve : Delete spaces from filenames??

Answer»

Hi,
Is it somehow possible (using DOS/batch PROG) to delete all space occurenses in filenames? The space(s) are not i a certain place, but can OCCUR wherever in the filename.

Ex.
f ile.txt
fil e.txt
file .txt

Many thanks!
-ronThis is a trick question, right? Using your example, the code will crash and burn with duplicate file names.

Code: [Select]
@echo off
for /f "tokens=1-2 delims=." %%a in ('dir /b DIRNAME') do (
for /f "tokens=1-6" %%i in ("%%a") do (
for /f %%x in ("%%b") do (
ren "dirname\%%a.%%b" %%i%%j%%K%%l%%m%%n.%%x
)
)
)


Replace dirname with a valid value. This will work for up to six embedded spaces. If you SUSPECT you have more, change accordingly.

Happy Computing...



Discussion

No Comment Found