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
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
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
Summary: Hello, I need to remove some information from textpad containing numbers and address(s). In the example, someone sends me information that contains people information with numbers starting. If I did a...
Summary: I want to call a file path in cmd.exe that contains blank spaces C:\Program Files\MyTxtFiles\*.txt Surrounding this path in quotation marks does not work, I think because of *.txt I need the path to ...
Summary: You'd need a language that can load and use .DLL's. Batch and VBScripts cannot. Failing that, there's always third party apps. Or you could write one yourself; it'd only be a few dozen lines in C or ...