![]() |
IOBit Software
|
|
|
||||||
| Programming Place to discuss programming including HTML, Java, C++, MySQL and others. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi Everyone,
I have 500 files coming in and I need to first check if any file(s) exist then rename all of them regardless of what their filename is (the files are named in a different language). No need to process them in any order. Rename: 1. “¦X¼d¬f-20110703-¦+¦dñHÑ-ª-¦=¬¦.xls” 2. “¦X¼d¬f-20110707-¦+¡¦-+¡8.xls” 3. “¦X¼d¬f-20110707-¦+¡¦ñj¦«.xls” 4. “¦X¼d¬f-20110708-¦+¡¦¬M¼n.xls” 5. “¦X¼d¬f-20110713-¦d¼O¼n¦hÑP.xls” . . . 500 To: “TWN_CH_INV_VISIT_FORM_01.xls” “TWN_CH_INV_VISIT_FORM_02.xls” “TWN_CH_INV_VISIT_FORM_03.xls” “TWN_CH_INV_VISIT_FORM_04.xls” “TWN_CH_INV_VISIT_FORM_05.xls” . . . “TWN_CH_INV_VISIT_FORM_500.xls” Hope you could help me on this one. I’ve been trying to do this for weeks. Thanks! |
| Sponsored links |
|
|
|
#2
|
||||
|
||||
|
Place that batch into the same folder ...
Code:
@echo off &setlocal enabledelayedexpansion
set /a n=1
for /f "delims=" %%i in ('dir /a-d /b *.xls') do (
set /a x=100!n! , n+=1
ECHO ren "%%i" "TWN_CH_INV_VISIT_FORM_!x:~-3!.xls"
)
PAUSE
Regards GermanOne |
|
#3
|
|||
|
|||
|
Thanks German One!
It showed the correct output. However, when I remove the ECHO and PAUSE, I get this error: "The system cannot find the file specified." Was there something I need to add on your script? Here's what I'm running. notice the removed echo: Code:
@echo off &setlocal enabledelayedexpansion
set /a n=1
for /f "delims=" %%i in ('dir /a-d /b *.xls') do (
set /a x=100!n! , n+=1
ren "%%i" "TWN_CH_INV_VISIT_FORM_!x:~-3!.xls"
)
|
| The Following User Says Thank You to r0mmel For This Useful Post: | ||
theefool (07-29-11) | ||
|
#4
|
||||
|
||||
|
Well I guess if this batch script doesn't work you have a problem with the characters in your file names. Maybe there are some unprintable characters which the forum software doesn't display.
Try the same using VBScript. Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objFSO.GetParentFolderName(WScript.ScriptFullName))
i = 0
For Each objFile In objFolder.Files
If LCase(objFSO.GetExtensionName(objFile.Name)) = "xls" Then
i = i + 1
objFSO.MoveFile objFile.Name, "TWN_CH_INV_VISIT_FORM_" & Right("00" & i, 3) & ".xls"
End If
Next
GermanOne |
|
#5
|
|||
|
|||
|
It worked! Thanks a lot GermanOne.
![]() |
| Sponsored links |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Write Batch files to script (Jython) | potchi | Software | 0 | 05-16-11 23:13 |
| Need help converting UNIX shell script to DOS batch script | vanco2001 | Programming | 3 | 04-16-11 03:08 |
| Odd suffix attached to .pdf files | Conklin | Software | 3 | 08-01-06 12:47 |
| help writing a script,batch or reg file to delete files | Integer | Programming | 2 | 10-10-03 18:56 |
| help writing a script,batch or reg file to delete files | Integer | Programming | 0 | 10-10-03 17:04 |