BrotherBrave
BrotherBrave

Reputation: 3

Path Not Found error when copying files using wildcard

Source Code:

Const OverwriteExisting = TRUE
Dim strSafeDate, strSafeTime, strDateTime

strSafeDate = Right("0" & DatePart("d",Date), 2) & "." & Right("0" & DatePart("m",Date), 2) & "." & DatePart("yyyy",Date)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

strDateTime = strSafeDate & " - " & strSafeTime

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.CopyFile "\\Ilgglafnp02\sapoutput\PRD\SpiceWorksReports\CurrentReportFiles\TicketsRaised(All)\*.*", "\\Ilgglafnp02\sapoutput\PRD\SpiceWorksReports\Archive\TicketsRaised(All)\"& strDateTime & ".xls"
objFSO.DeleteFile "\\Ilgglafnp02\sapoutput\PRD\SpiceWorksReports\CurrentReportFiles\TicketsRaised(All)\*.*"

Details:

I'm trying to write a simple script that copies all files from one shared location on a network to another for archiving purposes.

When I specify the name of the origin file like this:

objFSO.CopyFile "\\Ilgglafnp02\sapoutput\PRD\SpiceWorksReports\CurrentReportFiles\TicketsRaised(All)\HelloWorld.xls", 

The file is copied to the Archive folder and renamed to the current date and time - which is correct, and the file in the origin folder is deleted as it should be.

However, when I change this script to try to move all files from this folder, I get the following error message:

Script: Reporting.vbs
Line:   16
Char:   1
Error:  Path not found
Code:   800A004C
Source: Microsoft VBScript runtime error

This is confusing me because the DeleteFile line uses the same directory path and also uses the "." wildcard, but this gives no errors or issues when the script is run specifying the origin filename.

I know there is xcopy, but I'd really like to avoid this as much as possible.

Upvotes: 0

Views: 2298

Answers (1)

MC ND
MC ND

Reputation: 70923

You are trying to copy several source files into only one target .xls file, but the documentation states

If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files.

Your source includes wildcards, but your target is not a existing folder, and that is the cause of the error.

You have two options

  • first create a folder with the timestamp to copy all the files into it without any renaming
  • iterate over the files collection for the source folder, copying each file to a timestamped one in the target.

Upvotes: 1

Related Questions