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 strongm 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 1

Status
Not open for further replies.

sevi

IS-IT--Management
Jan 29, 2002
64
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

I've since been told that fso doesnt support wildcards.

Anyone got any ideas on how i can deal with this?

Cheers

Steve
 
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

 
That doesnt work. no error seems to be generated. It just doesnt find a file to process.

No one know how i can copy some files using a wildcard?? I didnt think it could be so difficult!!
 
Can you repose the question? What source files (if it involves some wildcard whatever it means then in what folder, with what kind of file's signature?) What destination?
 
I created the script as in my first post, but here it is again.

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

I basically want to copy a series of .dat files from c:\sfdcprodtran\BWSFDC and paste to c:\sfdcprodtran\BW.

The files are numbered sequentially from 000001 to 999999 and the filenames start with UB. so eg the first one is UB000001.dat and the second one UB000002.dat etc.

So if i were using dos, i would use the command:

COPY D:\SFDCPRODTRAN\BWSFDC\UB*.DAT C:\SFDCPRODTRAN\BW

where * is a wildcard.

any ideas??
 
I use the most basic string operation to do the wildcard selection, for easy comprehension.
[tt]
BWUPLOAD = "c:\sfdcprodtran\BW\" 'end with backslash
set ofolder=fso.getfolder("c:\sfdcprodtran\BWSFDC")
for each f in ofolder.files
if strcomp(left(f.name,2),"UB",1)=0 and strcomp(right(f.name,4),".dat",1)=0 then
fso.copyfile f.path,BWUPLOAD,true
end if
next[/tt]
 
Again, guitarzan suggested this:
Code:
BWFILE = "c:\sfdcprodtran\BWSFDC\UB*.dat"
BWUPLOAD = "c:\sfdcprodtran\BW\"
On Error Resume Next
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

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Cheers. Just trying this and keep getting an error.

error object required: 'fso'

This is against the second line.

ANy ideas??
 
Well, you don't have fso, and you keep using it!!! Add this at top.
[tt]
set fso=createobject("scripting.filesystemobject")
[/tt]
 
> BWFILE = "c:\sfdcprodtran\BWSFDC\UB*.dat"

> COPY D:\SFDCPRODTRAN\BWSFDC\UB*.DAT C:\SFDCPRODTRAN\BW

Ummmmmmmmmm could this be your problem??
 
Cheers for your help tsuji, thats worked!!

guitarzan, the dos command i showed was just an example that i quickly typed in and so the D:\ was just a typeo in the question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top