Post Reply 
Help with DOS batch file please
07-30-2014, 06:13 PM
Post: #1
Help with DOS batch file please
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!

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
07-30-2014, 06:58 PM
Post: #2
RE: Help with DOS batch file please
Bulk File Manager seems to be specifically made for your situation:

Bulk File Manager Home
Find all posts by this user
Quote this message in a reply
07-30-2014, 07:23 PM
Post: #3
RE: Help with DOS batch file please
For this kind of task under Windows I use a powerful freeware: Bulk Rename Utility.
Find all posts by this user
Quote this message in a reply
07-30-2014, 07:45 PM
Post: #4
RE: Help with DOS batch file please
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

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
07-30-2014, 08:01 PM
Post: #5
RE: Help with DOS batch file please
...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

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
07-30-2014, 08:30 PM
Post: #6
RE: Help with DOS batch file please
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

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
07-30-2014, 09:30 PM
Post: #7
RE: Help with DOS batch file please
You guys are amazing! Thanks so much! [Image: notworthy.gif]

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
07-30-2014, 09:34 PM
Post: #8
RE: Help with DOS batch file please
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
Find all posts by this user
Quote this message in a reply
07-31-2014, 12:54 AM (This post was last modified: 07-31-2014 12:55 AM by Claudio L..)
Post: #9
RE: Help with DOS batch file please
(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
Find all posts by this user
Quote this message in a reply
07-31-2014, 09:40 AM
Post: #10
RE: Help with DOS batch file please
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
Find all posts by this user
Quote this message in a reply
07-31-2014, 07:13 PM
Post: #11
RE: Help with DOS batch file please
(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

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
08-01-2014, 02:27 AM
Post: #12
RE: Help with DOS batch file please
(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!

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: