Saved Bookmarks
| 1. |
Solve : Renaming Files in DOS with *.*? |
|
Answer» HELLO, I have files named 111-1_001.tif 111-1_002.tif 111-1_003.tif 112-4_001.tif 112-4_002.tif I need to replace the -1 and -4 with -0001 and -0004 respectively to end up with: 111-0001_001.tif 111-0001_002.tif 111-0001_003.tif 112-0004_001.tif 112-0004-0002.tif I've tried the following: Code: [Select]rename 111-1*.* 111-0001*.* and Code: [Select]rename *-1* *-0001* but nothing seems to work. Anyone have an idea of how I can change these? I have thousands of files in this format. Ideally I'd like to replace all of the -1 with -0001, or rename all of the 111-1 to 111-0001, etc. Each of the prefix's (111) will have -1 through -999. Anyone have a magical DOS command I can do this with? I'm trying to use it in a batch file. A GUI interface just isn't going to fly with my intended user. Thanks!you got to use a for loop. however i have shown EXAMPLES of this before in vbscript. SEE hereThanks for your script GhostDog. If you wouldn't mind, can you help me with the specifics of your script? I'm not well versed in vbscript. In my exisitng folder I have the following files; 565-9-0001.tif 565-9-0002.tif 565-9-0003.tf I would like to replace 565-9- with 565-0009- Here is a copy of the script from your previous message. I changed as many of the paramaters as I could figure out: Code: [Select]Dim FSO,NewPrefix, OldPrefix, oDir, objFolder,NewFileName,counter NewPrefix="565-0009-" Set FSO = CreateObject("Scripting.FileSystemObject") sDir = "i:\chavez county\unzipped" Set objFolder = FSO.GetFolder(sDir) counter = 1 For Each Files In objFolder.Files If FSO.GetExtensionName(Files) = "565-9-" Then NewFileName = NewPrefix & Padding(3,counter) & ".tif" Files.Name = NewFileName counter=counter+1 End If Next Function Padding(ValueToPad, TheDigits) theLen = Len(TheDigits) If theLen < ValueToPad Then Padding = String(ValueToPad-theLen,"0") & TheDigits Else Padding = TheDigits End If End Function Quote from: bmacbmac on July 12, 2007, 11:35:15 PM Code: [Select]Dim FSO,NewPrefix, OldPrefix, oDir, objFolder,NewFileName,counter just a minor change. You can try the batch one at the link i gave if you are more inclined to batch programming. If you want to learn vbscript, you can download this |
|