Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


rename xls in a new folder and keep existing xls files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,53095
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> rename xls in a new folder and keep existing xls files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 rename xls in a new folder and keep existing xls files - 10/27/2007 9:47:00 AM   
  azheri

 

Posts: 1
Score: 0
Joined: 10/27/2007
Status: offline
very new to vbscript

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim strCurrentFolder
strCurrentFolder = "c:\source folder"
Dim objFolder
Set objFolder = objFSO.GetFolder(strCurrentFolder)

ListDirectory objFolder

Sub ListDirectory(objFolder)
Dim objFile
Dim objSubFolder

For Each objFile In objFolder.Files
  If UCase(Right(objFile.Path, 3)) = "xls" Then
      objFSO.MoveFile objFile.Path, strcurrentfolder & NewFileName
          wscript.quit
  End If  
Next
End Sub

this code deletes xls files after it moves them
 
 
Post #: 1
 
 RE: rename xls in a new folder and keep existing xls files - 10/27/2007 10:04:12 PM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi azheri,

if you want to keep the original file, use copy instead of move. In
both case, the target of the action has to be specified correctly.
I suspect the your "NewFileName" doesn't do this. You should
echo source and destination path/file spec to make sure, before
the action.

Good luck!

ehvbs

(in reply to azheri)
 
 
Post #: 2
 
 RE: rename xls in a new folder and keep existing xls files - 11/5/2007 4:16:51 PM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
the function "FSO.MoveFile" is FSO's way of renaming a file.  it renames the original file, does not delete it.  that's why you dont see the original file any more afer it's been "FSO.movefile."  what your looking for is "FSO.CopyFile" this will copy the file and leave original intact.

change this:

objFSO.MoveFile objFile.Path, strcurrentfolder & NewFileName

to:

objFSO.CopyFile objFile.Path, strcurrentfolder & NewFileName

(in reply to ehvbs)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> rename xls in a new folder and keep existing xls files Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts