IDNetters Forums

Technical News & Discussion => Windows News & Discussion => Topic started by: mrapoc on Oct 19, 2008, 16:03:14

Title: Search and replace text in windows?
Post by: mrapoc on Oct 19, 2008, 16:03:14
Hey guys

im after a tool to search for a certain character or whatever in whichever directory I specify and replace it with something else

In this example I have a lot of "_" in my music collection folder titles for example:

High_Contrast-Tough_Guys_Dont_Dance

i need a program to search, find and replace the _ with a space (ideally)

cheers
Title: Re: Search and replace text in windows?
Post by: Simon on Oct 19, 2008, 16:42:45
I'd find that useful too, but have never come across anything that can do it.
Title: Re: Search and replace text in windows?
Post by: Rik on Oct 19, 2008, 16:45:41
Everything I've seen works on text within files, Sam, but I can't think of one that works on file names. I'm just wondering, though, whether anything could be done with a batch file?
Title: Re: Search and replace text in windows?
Post by: Sebby on Oct 19, 2008, 16:49:26
In one batch file:

for /r c:\filestorename\ %%K in (*.*) do call c:\rename.bat "%%K"
pause
exit


Then in rename.bat:

@echo off
set fname="%~n1"
set ext=%~x1
set fname=%fname:_= %
ren "%~f1" %fname%%ext%
)


Very rough and ready, but tested and working. :)

It could be spruced up a bit to perhaps ask for the directory that contains the files to be renamed, for example.
Title: Re: Search and replace text in windows?
Post by: Rik on Oct 19, 2008, 16:51:21
Thanks, Sebby.  :thumb:
Title: Re: Search and replace text in windows?
Post by: mrapoc on Oct 19, 2008, 19:19:30
excellent :)

edit:

how do i use it

i put it in my music directory and as follows

1st batch:

for /r D:\My Music\ %%K in (*.*) do call D:\My Music\rename.bat "%%K"
pause
exit


rename batch:

@echo off
set fname="%~n1"
set ext=%~x1
set fname=%fname:_= %
ren "%~f1" %fname%%ext%
)
Title: Re: Search and replace text in windows?
Post by: Sebby on Oct 19, 2008, 20:13:30
You probably need to do "D:\My Music\" and "D:\My Music\rename.bat" because of the spaces.
Title: Re: Search and replace text in windows?
Post by: Dopamine on Oct 19, 2008, 21:29:12
I use the freeware Bulk Rename Utility, which amongst many options has a "replace x with y" function.

http://www.bulkrenameutility.co.uk/Main_Intro.php
Title: Re: Search and replace text in windows?
Post by: Sebby on Oct 19, 2008, 21:29:33
That's much better than my solution, thanks. :thumb: