Computing.Net > Forums > Programming > Replace Underlines with spaces

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Replace Underlines with spaces

Reply to Message Icon

Name: aegis
Date: April 22, 2008 at 17:36:21 Pacific
OS: XP Home Sp2
CPU/Ram: AMD 3800 64
Product: Generic
Comment:

I sure could use a batch file to modify the filenames of all the files in a folder. I need to replace the 'underlines' with 'spaces'. I would really appreciate it if someone would help me out?



Sponsored Link
Ads by Google

Response Number 1
Name: aegis
Date: April 22, 2008 at 17:44:03 Pacific
Reply:

Sorry about that! I found out that I have a renamer program to do it.
However if someone wants to bother to create a batch file to do it, I could use it and maybe learn something.


0

Response Number 2
Name: Mechanix2Go
Date: April 22, 2008 at 23:47:59 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set old=%%a
set new=!old:_= !
echo ren !old! !new!
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: aegis
Date: April 23, 2008 at 09:19:32 Pacific
Reply:

Thanks very much Mechanix2Go!!!
I'll use it instead of the renamer program. I've downloaded a XP Batch tutorial. I'm gonna study that code and see if I can't learn some more about batch programming.


0

Response Number 4
Name: klint
Date: April 23, 2008 at 09:27:00 Pacific
Reply:

I'd just like to point out a minor problem, when you have spaces in a file it should be enclosed in quotes, so the above should be:

ren !old! "!new!"

(In fact you may even need to enclose !old! in quotes too, just in case there are spaces in the old filename even though it uses underlines.)


0

Response Number 5
Name: aegis
Date: April 23, 2008 at 10:52:31 Pacific
Reply:

Thanks very much Klint. That helps a lot. I'm an old DOS guy with very minimal batch knowledge. I'm amazed at how sophisticated it has become.


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: April 23, 2008 at 21:24:57 Pacific
Reply:

Hi klint,

Exactly right. I'm always thinking of 8.3 names. LOL


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: aegis
Date: April 24, 2008 at 12:59:02 Pacific
Reply:

First I want to thank you both for helping me out. I ran into one 'strange' problem. The routine seemed to work perfectly fine. It did output the rename commands correctly, but the system seemed to ignore them. I finally tried changing the:

echo ren "!old!" "!new!"
to
ren "!old!" "!new!"

and then it worked.

Anyway, thanks very much! It's a lot easier than using the renamer program.


0

Response Number 8
Name: klint
Date: April 25, 2008 at 02:06:28 Pacific
Reply:

The echo command was used purely for testing prior to deployment. Commands such as REN can cause major problems if used incorrectly, and therefore it's a good idea to add "echo" in front of them when you first try your batch file so that it tells you what it would do, without actually doing it. When you've checked that it does the right thing, you simply remove the ECHO, just as you've done.


0

Response Number 9
Name: aegis
Date: April 25, 2008 at 09:01:47 Pacific
Reply:

Thanks again Klint. I should have thought of that, but I'm a senile old (78) man and I'm pretty slow. I'll 'try' and remember that excellent tip.

Can I ask you just 'one' more (I promise) question? How do you determine if a directory is empty? I have tried 'if exist file' and it doesn't seem to work right under XP.

I'm trying to search a bunch of sub folders to see if any files have been added. I do a dir on each folder and get the new files displayed, but the problem is that I get a 'File not found' line for each empty folder. I was hoping for a way to determine if the folder is empty before doing the dir.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Batch file. Extract singl... get current folder name i...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Replace Underlines with spaces

find and replace ultra with extra in files www.computing.net/answers/programming/find-and-replace-ultra-with-extra-in-files/19290.html

Compare two text files with spaces www.computing.net/answers/programming/compare-two-text-files-with-spaces/19886.html

Replacing space tab with | www.computing.net/answers/programming/replacing-space-tab-with-/20246.html