HP Forums

Full Version: Help with DOS batch file please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Sorry for this TOTALLY non-HP calculator request, but I'm at wit's end here and this is a geeky enough group that I'll bet somebody here will know the answer.

I have a bunch of files on my PC with names like this:

foo.FRED.txt
bar.FRED.txt
fumtu.FRED.txt
snafu.FRED.txt
and so on. A zillion of 'em.

I want to remove the redundant ".FRED" from all the names, preserving the rest of the name. There MUST be a way of writing a simple .BAT file that does this.... but every attempt I've made so far has been disastrous and I'm going nuts.

FWIW, all I have is the CMD window of Windows 7, not anything nice like 4DOS.

Several hours of searching the web has proved fruitless. Thanks in advance for any help you can offer!
Bulk File Manager seems to be specifically made for your situation:

Bulk File Manager Home
For this kind of task under Windows I use a powerful freeware: Bulk Rename Utility.
You can do it in less than a minute with Excel (or similar app) and cmd (just shift+right click to Copy the file paths):
http://www.screencast.com/t/dKKIR579rG
...or you can simply use the included PowerShell. Put the following in the file renm.ps1:

Code:
Dir | Rename-Item –NewName { $_.name –replace ".FRED","" }

then start PowerShell or, at the command prompt:
Code:
powershell .\renm.ps1
Or... cmd anyways:

Code:
for /f "delims=" %%i in ('dir /b') do call :rename "%%~fi"
goto end
:rename
set a=%1
set a=%a:TEXT_TO_REMOVE=%
move %1 %a%
:end
You guys are amazing! Thanks so much! [Image: notworthy.gif]
I know this will be no use to Joe, but in case anybody's interested in the Linux way, just open a Bash terminal and type the command:

for F in *.FRED.txt; do mv $F ${F/.FRED}; done
(07-30-2014 06:13 PM)Joe Horn Wrote: [ -> ]FWIW, all I have is the CMD window of Windows 7, not anything nice like 4DOS.

Since you think 4DOS was nice, did you know you can still have it in Windows, and for free? I have it in all my Windows boxes.
Search for TCC/LE (that's the new name of 4DOS for windows) from JPSoft, it's free if you want the equivalent of 4DOS. The paid version is way more advanced and with a GUI.

Claudio
I realize this has already been answered. Being an old PC/DOS user I had a different approach. I have VISTA Home Premium SP2 specifically. Maybe that makes no difference; haven't kept up with nuances of Windows for years.

Test & verify on your system by a using a temp directory and a few sample files and use the following DOS commands from at the c:\temp> prompt

rename *.FRED.txt *.
rename *.FRED *.txt

---------------------------------------------------------

rename *.FRED.txt *.
-->> produces *.FRED

rename *.FRED *.txt
-->> produces *.txt
(07-31-2014 09:40 AM)Duane Hess Wrote: [ -> ]I realize this has already been answered. Being an old PC/DOS user I had a different approach. I have VISTA Home Premium SP2 specifically. Maybe that makes no difference; haven't kept up with nuances of Windows for years.

Test & verify on your system by a using a temp directory and a few sample files and use the following DOS commands from at the c:\temp> prompt

rename *.FRED.txt *.
rename *.FRED *.txt

---------------------------------------------------------

rename *.FRED.txt *.
-->> produces *.FRED

rename *.FRED *.txt
-->> produces *.txt

:O!!! this is the best solution by far! so simple! kudos
(07-31-2014 07:13 PM)eried Wrote: [ -> ]
(07-31-2014 09:40 AM)Duane Hess Wrote: [ -> ]Test & verify on your system by a using a temp directory and a few sample files and use the following DOS commands from at the c:\temp> prompt

rename *.FRED.txt *.
rename *.FRED *.txt

:O!!! this is the best solution by far! so simple! kudos

Indeed! Most elegant. Thanks, Duane!
Reference URL's