Subscribe to
Posts
Comments

After writing previous post about using window

batch command to rename all files in a folder I found using VB Script to do the same thing is much easier.

Let’s say you have a few thousand files named in the same pattern like transaction_xxxxx.txt in a folder called test. You want to rename all these files so that they are named like trans_xxxxx.txt. Here is the VB Script code to do that.

Dim fso,f

Set fso=CreateObject(”Scripting.FileSystemObject”)
Set f = fso.GetFolder(”d:/test”)
For Each file In f.Files
fso.MoveFile file.Name, Replace(file.Name,”Transaction”,”Tran”)
Next

Set f = Nothing
Set fso = Nothing

Put the above code into a text file, rename the text file to rename.vbs and put it into the test folder. Double click on the vbs file to execute it. And that is it.


Related Posts:

  • Batch Script on Windows: Using For Loop to Rename All Files in a Folder
  • The Best Way to Upgrade Wordpress
  • How to Trouble Shoot SQL Server Job Error 8198 - Unable to Determine if the Owner of Job Has Server Access
  • Restore the latest database backup automatically and xp_dirtree
  • Upgrade WordPress From 2.12 to 2.50 to Prevent Being Hacked


  • 1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.5 out of 5)
    Loading ... Loading ...

    RSS feed | Trackback URI

    5 Comments »

    Comment by Dylan81
    2009-03-09 17:37:08
    MyAvatars 0.2

    What if all the files have different names?
    Eg, all my photo files need renaming but they all have different naming conventions applied.
    Cheers.

     
    Comment by Andrew Chen
    2009-03-09 21:18:22
    MyAvatars 0.2

    I think it should be easy to replace the following line with some if statements to implement whatever naming convention you want to follow.

    fso.MoveFile file.Name, Replace(file.Name,”Transaction”,”Tran”)

    for example you can have

    if instr(file.name, “Transaction”)>0 then
    fso.MoveFile file.Name, Replace(file.Name,”Transaction”,”Tran”)
    end if

     
    Comment by SenHu Subscribed to comments via email
    2009-04-08 06:23:32
    MyAvatars 0.2

    Andrew:

    Sounds like you enjoy posting automation scripts based on new ideas. I appreciate that - your effort helps out a lot of people.

    Have you looked at biterscripting (http://www.biterscripting.com for free installation) ? It is simple to learn, but you can take it to a cerebral level. Documentation is available with the ‘help’ command. It is my guess that you will probably like posting scripts in biterscripting.

    Sen

    Comment by Andrew Chen
    2009-04-10 15:10:14
    MyAvatars 0.2

    Thank Sen! I will check that out :smile:

     
     
    Comment by Bo
    2011-08-19 10:58:39
    MyAvatars 0.2

    I know this post is really old, but I just wanted to let you know that I looked all over the place for a solution like this and finally stumbled across your post. It was exactly what I needed.

    I did have to retype all of the quotation marks into the script once I copied and pasted it into notepad. Windows doesn’t like the ones that were in your post.

    Thanks a million!!

     
    Name (required)
    E-mail (required - never shown publicly)
    URI
    Subscribe to comments via email
    Your Comment (smaller size | larger size)
    You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.