Computing.Net > Forums > Programming > File rename in CMD or Bat script

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.

File rename in CMD or Bat script

Reply to Message Icon

Name: dengar7948
Date: August 29, 2006 at 07:14:48 Pacific
OS: Window XP/2003
CPU/Ram: Intel
Product: Any
Comment:

I have a directory with files that all have a prefix where I need to have a cmd or bat script to remove the prefix for all files in the directory. I know how to write a script that renames the files to add the prefix to all files but I don't know how to rename all files to remove the prefix.

Example: I have a directory which has 4000 files that all begin with prefix_filename.txt
I need to have all the files renamed to:
filename.txt

Any help would be great.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: tonysathre
Date: August 29, 2006 at 12:40:54 Pacific
Reply:

Try this:

:: renamer.bat
@echo off

:main
for %%f in (abc*.txt) do call :renamer %%f
goto :eof

:renamer
set old=%1
ren %1 %old:~3,9%
:: end

This will remove the first 3 letters of the filename.

login: yes
password: dont have one

password is incorrect

login: yes
password: incorrect


0

Response Number 2
Name: tonysathre
Date: August 29, 2006 at 12:46:21 Pacific
Reply:

Oops, that will only work if the prefix is abc, so just change abc*.txt to whatever your prefix is. The part :~3,9% will remove the first 3 letters, so change that to reflect how many letters your prefix is.

Hope that helps.

Tony

login: yes
password: dont have one

password is incorrect

login: yes
password: incorrect


0

Response Number 3
Name: wizard-fred
Date: August 29, 2006 at 22:56:01 Pacific
Reply:

There are also programs that will rename filenames with changeable parameters. i.e. replacing, removing, or adding characters, numbering or renumbering, etc.


0

Response Number 4
Name: dengar7948
Date: August 30, 2006 at 05:44:34 Pacific
Reply:

That worked. Thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: File rename in CMD or Bat script

Need VB or .bat script for Textpad. www.computing.net/answers/programming/need-vb-or-bat-script-for-textpad/17282.html

Blank Spaces in cmd www.computing.net/answers/programming/blank-spaces-in-cmd/14095.html

Set the screen size buffer in VBScript or bat www.computing.net/answers/programming/set-the-screen-size-buffer-in-vbscript-or-bat/19904.html