Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Delete spaces from filenames?  (Read 4321 times)

0 Members and 1 Guest are viewing this topic.

_ron_

  • Guest
Delete spaces from filenames?
« on: August 17, 2005, 01:43:57 AM »
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!
-ron

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Delete spaces from filenames?
« Reply #1 on: August 17, 2005, 06:47:05 AM »
This 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... 8)
« Last Edit: August 17, 2005, 06:49:07 AM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein