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

VB Script & Wildcards

Status
Not open for further replies.

sevi

IS-IT--Management
Jan 29, 2002
64
0
0
GB
I'm trying to get the (simple) bit of script to work.

If i put in the full filename of the file I am looking for, it works fine, but if i use the *(wildcard) it doesnt find the file.

I assume i've missed something simple and as you might have guessed, i'm no scipter!!


Set fso = CreateObject("Scripting.FileSystemObject")

BWFILE = "c:\sfdcprodtran\BWSFDC\UB*.dat"
BWUPLOAD = "c:\sfdcprodtran\BW\"


If fso.FileExists (BWFILE) then
fso.CopyFile BWFILE, BWUPLOAD
end if

For Each file In fso.GetFolder(BWUPLOAD).Files

Wscript.echo "File found."

Next
 
The "FileExists" method does not accept wildcards.

In the future, you should use the VBScript forum here: forum329

 
The 'simple' thing that you have missed is that FSO (sadly) doesn't support wild cards.
 
Well, CopyFile does support wildcards (for the source parameter, anyway)
 
So it seems from the responses.....

Can anyone help / suggest an alternative way of dealing with this??

Cheers

Steve
 
What happens if you simply remove the "FileExists" If/Then?
 
It works.

Its just dealing with the copy part.
 
CopyFile will return an error if no files match the "source" criteria. This error can be trapped, and you can deal with it accordingly. Since you haven't said that you received an error, I'm guessing that you have the line "ON ERROR RESUME NEXT" somewhere in your script, which let's the script continue after an error is encountered.

This error can still be trapped, and you can take whatever steps you need. A generic example:

fso.CopyFile BWFILE, BWUPLOAD
If err.number <> 0 then
Wscript.echo "Got Error " & err.number & ": " & err.description
Else
Wscript.echo "The copy worked."
End If

 
Yes, sorry; the 'simple' thing that you have missed is that the 'FileExists' method of FSO (sadly) doesn't support wild cards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top