MajorGeeks Support Forums

Go Back   MajorGeeks Support Forums > ----------= PC, Desktop and Laptop Support =---------- > Software
Register FAQ Members List Calendar Casino Mark Forums Read

Software Software such as operating systems like Windows XP, Windows Vista, Windows 7 etc., or specific programs.


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. Xdf-20110703-+dH--=.xls
2. Xdf-20110707-+-+8.xls
3. Xdf-20110707-+j.xls
4. Xdf-20110708-+Mn.xls
5. Xdf-20110713-dOnhP.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. Ive 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
Major Geek's Coding Genius Extraordinaire
 
Join Date: Feb 2009
Location: Thuringia / Germany
Posts: 314
Thanks: 4
Thanked 68 Times in 65 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
Major Geek's Coding Genius Extraordinaire
 
Join Date: Feb 2009
Location: Thuringia / Germany
Posts: 314
Thanks: 4
Thanked 68 Times in 65 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 Software 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 Software 2 10-10-03 18:56
help writing a script,batch or reg file to delete files Integer Software 0 10-10-03 17:04


All times are GMT -5. The time now is 10:57.

MajorGeeks.Com Menu

MajorGeeks.Com \ All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ NEW! PC Games \ System Tools \ Macintosh \ Demonews.Com \ Top Downloads

MajorGeeks.Com \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds


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