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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move File to Archive

Status
Not open for further replies.

vgwprja

Programmer
Mar 27, 2008
24
0
0
US
Below script moves files to the /Archive folder. In some cases the file may already exists in archive and if so is there a way to replace?


For Each objFile In fileColl
If objRegExp.Test(objFile.Name) Then
On Error Resume Next
filesys.MoveFile objFile, folderName & "archive\" & newFile
On Error Goto 0
End If
Next
 
For Each objFile In fileColl
If objRegExp.Test(objFile.Name) Then
strDest = folderName & "archive\" & newFile
If filesys.fileExists(strDest) Then filesys.DeleteFile strDest
filesys.MoveFile objFile, strDest
End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Just making sure I have it correct (I need some error trapping as well):

For Each objFile In fileColl
If objRegExp.Test(objFile.Name) Then
strDest = folderName & "archive\" & newFile
If filesys.fileExists(strDest) Then filesys.DeleteFile strDest
filesys.MoveFile objFile, strDest
If Err.Number <> 0 Then
objEmail.Subject = "Travelers - ftp error in procedure: Travelers_Inbound_Archive_Encrypted_FTP_Files.vbs"
objEmail.Textbody = "File: " & objfile & " in Folder: " & foldername & " Process: Archive outbound FTP file(s) failed: " & Err.Number & ") - " & Err.Description
objEmail.Send
Err.Clear
End If
End If
Next
 
>Just making sure I have it correct (I need some error trapping as well):
What do you want to say? You mean you come up finally that that incorporate your additional need? or that you copy and paste again for the forum to see if there is something wrong? Why can you not be more clear? It is your script, why can you not test it before posting back?
 
Sorry about the confusion. The latests script posted does not work. If the file already exists in the archive folder it gives an error.

If file exists in the archive folder I need to delete it prior to moving a new file into same folder.

Thank you.
 
What is newFile ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I am archiving files located in folder "e:\fromtravelers" (ie folderName = "e:\ftpdata\fromtravelers\") to folder e:\fromtravelers\archive. Files in folder "fromtravelers" may already exist in "archive" and it so I need to replace them with files from "e:\fromtravelers".
 
Hi
vgwprja
Would you put ur entire script ? Trying to understand.

THX
 
Code:
For Each objFile In fileColl
  If objRegExp.Test(objFile.Name) Then
    strDest = folderName & "archive\" & objFile.Name
    If filesys.fileExists(strDest) Then filesys.DeleteFile strDest
    filesys.MoveFile objFile, strDest
  End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
>[tt]filesys.MoveFile objFile, strDest[/tt]
Should do, but better leave no space of doubt.
[tt]filesys.MoveFile objFile.path, strDest[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top