HP Forums
Help with DOS batch file please - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not remotely HP Calculators (/forum-9.html)
+--- Thread: Help with DOS batch file please (/thread-1892.html)



Help with DOS batch file please - Joe Horn - 07-30-2014 06:13 PM

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!


RE: Help with DOS batch file please - everettr - 07-30-2014 06:58 PM

Bulk File Manager seems to be specifically made for your situation:

Bulk File Manager Home


RE: Help with DOS batch file please - Didier Lachieze - 07-30-2014 07:23 PM

For this kind of task under Windows I use a powerful freeware: Bulk Rename Utility.


RE: Help with DOS batch file please - eried - 07-30-2014 07:45 PM

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


RE: Help with DOS batch file please - Massimo Gnerucci - 07-30-2014 08:01 PM

...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



RE: Help with DOS batch file please - eried - 07-30-2014 08:30 PM

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



RE: Help with DOS batch file please - Joe Horn - 07-30-2014 09:30 PM

You guys are amazing! Thanks so much! [Image: notworthy.gif]


RE: Help with DOS batch file please - r. pienne - 07-30-2014 09:34 PM

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


RE: Help with DOS batch file please - Claudio L. - 07-31-2014 12:54 AM

(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


RE: Help with DOS batch file please - Duane Hess - 07-31-2014 09:40 AM

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


RE: Help with DOS batch file please - eried - 07-31-2014 07:13 PM

(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


RE: Help with DOS batch file please - Joe Horn - 08-01-2014 02:27 AM

(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!