Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help to rename part of file

Help to rename part of file

Help to rename part of file

Good morning all,

I have hundreds of pdf files like V-45X-0892-0.pdf, V-45X-0893-0.pdf, etc...
I would like to strip the -0 on end of every filename to look like V-45X-0892.pdf, V-45X-0893.pdf, etc..

Any help would be greatly appreciated.

Below is what I have but not working:

folderspec = "C:\Dave\"
strRename = ""

set fs = CreateObject("Scripting.FileSystemObject")
set f = fs.GetFolder(folderspec)

for each f1 in f.files
Filename = folderspec & f1.name
NewFilename = replace(Filename, "*-0.pdf" "*.pdf", strRename)
fs.MoveFile Filename, NewFilename

msgbox "All Done"

Thank you in advance,

RE: Help to rename part of file

Something like the below:


folderspec = "C:\Dave\"
strRename = ""

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)

For Each f1 In f.Files
    f1.Move fs.BuildPath(f1.ParentFolder, Replace(f1.Name, "-0.", "."))

MsgBox "All Done" 

RE: Help to rename part of file


That did the trick! Thank you so much! I really appreciate it.


RE: Help to rename part of file

Maybe this is faster, processing names and renaming only those files that have to be renamed:

CODE -->

For Each f1 In f.Files
    Filename = f1.Name
    If InStr(Filename, "-0.pdf") > 0 Then f1.Name = Replace(Filename, "-0.pdf", ".pdf")
Next f1 


RE: Help to rename part of file

combo, thank you for your input but it's not working. "Expected end of statement" error. Line:4

RE: Help to rename part of file

Seems that VBscript does not accept counter after Next, so try single Next in last line.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close