Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename file extension

Status
Not open for further replies.

mydisney

Programmer
May 7, 2007
55
US
I have a script that is supposed to rename any .pgp file extension to .bak and move files to a backup folder.

When I execute the script it looks like it selects more than just the .pgp extension (like .txt and .vbs). Any ideas?

'Rename .pgp files after ftp upload
Dim filesys, file, folderName, objFile, folderObj, fileColl, objRegExp, newFile
Set filesys = CreateObject("Scripting.FileSystemObject")

folderName = "c:\myfolder\myfiles\"
Set folderObj = filesys.GetFolder(folderName)
Set fileColl = folderObj.Files

Set objRegExp = New RegExp
objRegExp.Pattern = ".pgp" 'looking for .pgp (extension) match
objRegExp.IgnoreCase = True

For Each objFile In fileColl
newFile = objRegExp.Replace(objFile.Name, ".bak") 'replacing with .bak extension
filesys.MoveFile objFile, folderName & "backup\" & newFile
Next
 
Try changing

".pgp"

to

"\.pgp$"

and as it is you're moving all files regardless.

maybe

For Each objFile In fileColl
If objRegExp.Test(objFile.Name) Then
newFile = objRegExp.Replace(objFile.Name, ".bak")
filesys.MoveFile objFile, folderName & "backup\" & newFile
End If
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
That seemed to do the trick !!! Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top