Home / Microsoft / Microsoft DOS / Delete spaces from filenames?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Delete spaces from filenames?  (Read 1290 times)
_ron_
Guest
« 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
IP logged
Sidewinder
Guru



Thanked: 97
Posts: 4,341

Experience: Familiar
OS: Windows 7

« 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 » IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / Delete spaces from filenames? « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.093 seconds with 20 queries.