Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Script to Rename files

Posted on 2013-06-24
11
373 Views
Last Modified: 2013-06-24
I need a turnkey Windows script to rename all the files inside a folder in sequential order.  It does not matter the current filename or even the order of the files.  I just need all 5k audio files to be renamed to SP0000.wma, SP0001.wma, SP0002.wma, etc  Most of the current filenames have spaces in them.
0
Comment
Question by:murryc
  • 6
  • 4
11 Comments
 
LVL 7

Expert Comment

by:dec0mpile
ID: 39272813
Have you ever used this tool?

http://www.bulkrenameutility.co.uk/Download.php

This is what I use when I need to so such tasks. It comes with great deal of features and it is very flexible (can handle large amount of files).

Just as a reminder, weather you use script or a tool you should always make a backup of your files before you perform automated bulk operations on them.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39272835
What do you mean by "5k audio files"?

~bp
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39272881
If you just want to rename all WMA files, here's a script that will do that.  Adjust the pathname near the top.

strBaseDir = "C:\EE\EE28166360\Files"
strBaseExt = ".wma"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objBaseDir = objFSO.GetFolder(strBaseDir)

i = 0
For Each objFile in objBaseDir.Files
    If LCase(Right(objFile.Name, Len(strBaseExt))) = LCase(strBaseExt) Then
        i = i + 1
        objFSO.MoveFile objFile.Path, objFSO.GetParentFolderName(objFile.Path) & "\SP" & LPad(i, 4, "0") & strBaseExt
    End If
Next

Set objFSO = Nothing

' Right pad a string to any length with a specified character
Function RPad( strText, intLen, chrPad )
  RPad = Left( strText & String( intLen, chrPad ), intLen )
End Function

' Left pad a string to any length with a specified character
Function LPad( strText, intLen, chrPad )
  LPad = Right( String( intLen, chrPad ) & strText, intLen )
End Function

Open in new window

~bp
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:murryc
ID: 39272950
billprew...I have around 5 thousand files to rename

dec0mpile...I will review
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39273005
Ah, I get it, just the count of files.  Okay, then my script should be a good starting place, maybe doing everything needed.

~bp
0
 

Author Comment

by:murryc
ID: 39273023
bp, I executed the script but it just runs with no error or output.  I will wait and run it against your other script that extracts the audio files into a single folder.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39273043
Well, I ran a test here and it renamed the files.  What did you change the first 2 lines to?

~bp
0
 

Author Comment

by:murryc
ID: 39273082
strBaseDir = "D:\KKUS Tom Music"
strBaseExt = ".wma"
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39273100
Inside the "D:\KKUS Tom Music" do the files that exist have an extension of ".wma"?  That is the assumption in the script.  Or do they have some other name?

And the files are NOT in subfolders, right?

~bp
0
 

Author Comment

by:murryc
ID: 39273107
The are in subfolders, BUT they will all exist in the root once I run your other script (on the other question) to extract them.  They are all .wma but there are also other misc files just .jpg files mixed in there.  Those files just need to be left alone.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39273111
Okay, I get it, so this script shouldn't have done anything yet, fair enough.

~bp
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question