MajorGeeks Support Forums IOBit Software

Go Back   MajorGeeks Support Forums > Majorgeeks.Com - Support Forums > Programming
Register FAQ Members List Calendar Casino Mark Forums Read

Programming Place to discuss programming including HTML, Java, C++, MySQL and others.


Reply
 
Thread Tools Display Modes
  #1  
Old 07-14-11, 04:46
r0mmel r0mmel is offline
Private First Class
 
Join Date: Jul 2011
Posts: 30
Thanks: 2
Thanked 1 Time in 1 Post
Default How to rename and add incrementing number suffix on multiple files in Batch Script?

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!
Reply With Quote
Sponsored links
  #2  
Old 07-14-11, 12:08
GermanOne's Avatar
GermanOne GermanOne is offline
Corporal
 
Join Date: Feb 2009
Location: Thuringia / Germany
Posts: 297
Thanks: 4
Thanked 58 Times in 57 Posts
Default Re: How to rename and add incrementing number suffix on multiple files in Batch Scrip

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
... run it and check the output. If you believe it would rename the files the right way then remove ECHO and PAUSE for arming.

Regards
GermanOne
Reply With Quote
  #3  
Old 07-18-11, 22:39
r0mmel r0mmel is offline
Private First Class
 
Join Date: Jul 2011
Posts: 30
Thanks: 2
Thanked 1 Time in 1 Post
Default Re: How to rename and add incrementing number suffix on multiple files in Batch Scrip

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"
)
Reply With Quote
The Following User Says Thank You to r0mmel For This Useful Post:
theefool (07-29-11)
  #4  
Old 07-19-11, 16:49
GermanOne's Avatar
GermanOne GermanOne is offline
Corporal
 
Join Date: Feb 2009
Location: Thuringia / Germany
Posts: 297
Thanks: 4
Thanked 58 Times in 57 Posts
Default Re: How to rename and add incrementing number suffix on multiple files in Batch Scrip

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
Regards
GermanOne
Reply With Quote
The Following 2 Users Say Thank You to GermanOne For This Useful Post:
r0mmel (07-28-11), theefool (07-29-11)
  #5  
Old 07-28-11, 03:38
r0mmel r0mmel is offline
Private First Class
 
Join Date: Jul 2011
Posts: 30
Thanks: 2
Thanked 1 Time in 1 Post
Thumbs up Re: How to rename and add incrementing number suffix on multiple files in Batch Scrip

It worked! Thanks a lot GermanOne.
Reply With Quote
Sponsored links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -5. The time now is 17:31.


MajorGeeks.Com Home Page
| Admin Tools | All In One | Anti-Spyware | Anti-Virus | Appearance | Backup | Benchmarking | BIOS | Browsers | Covert Ops |
Data Recovery | Diagnostics | Drive Cleaners | Drive Utilities | Drivers | Driver Tools Ergonomics | Firewalls | Games | Game Tweaks | Graphics | Input Devices | Internet Tools | Macintosh | Mail Utilities | Memory | Messaging | Monitoring | Microsoft | Multimedia | Networking | Office Tools | Process Management | Processor | Registry | Security | System Info | Toys | Video | Miscellaneous
|

-->
Powered by vBulletin® Version 3.8.4
Copyright © 2009 vBulletin Solutions, Inc. All rights reserved.
Ad Management by RedTyger