Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Visual Basic (VB 4/5/6) » General Visual Basic » Wildcard searching for file to copy


Wildcard searching for file to copyExpand / Collapse
Author
Message
Posted 3/29/2005 2:52:21 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/29/2005 4:31:00 PM
Posts: 2, Visits: 1

I have to look through a particular network folder to find a file then copy it to another network share.  I have the format of the file name, but I need to do a wildcard search through the folder to get the complete filename before I can use

"filecopy sourcefile, destinationfile"

What is the code for finding a file that lets me use wildcards?

Thanks,

 



K
Post #10047
Posted 3/29/2005 4:11:10 PM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 2/28/2006 11:41:01 AM
Posts: 48, Visits: 3

Don't know about FileCopy but the File System Object would do the trick.

Private Sub Command1_Click()
Dim fso As FileSystemObject
Set fso = New FileSystemObject
fso.CopyFile "C:\*.mdb", "C:\Testit\"
MsgBox "Done!", vbInformation
End Sub

 



Swi
Post #10055
Posted 3/29/2005 4:19:40 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 1:10:14 PM
Posts: 1,502, Visits: 3,491

FileCopy copies a file to an other folder.

FileCopy "C:\Windows\Calc.exe, "C:\Temp\Calc.exe"

He was asking how to find a file.



Keith

http://www.martin2k.co.uk/forums/

I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #10056
Posted 3/29/2005 5:17:04 PM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 2/28/2006 11:41:01 AM
Posts: 48, Visits: 3

Quite an oversite.    Should have read the whole post.

Look up the DIR function in VB help and it will give you a good example of using wildcards.



Swi
Post #10059
Posted 3/29/2005 5:25:18 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 1:10:14 PM
Posts: 1,502, Visits: 3,491
Yes he wants to find a file then copy it. You code doesn't find anything.

Keith

http://www.martin2k.co.uk/forums/

I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #10060
Posted 3/29/2005 6:18:59 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 3/29/2005 4:31:00 PM
Posts: 2, Visits: 1

You're both right.  I was asking about finding a filename using wildcards so I could use the filecopy the way I outlined it in the original post.  However, I was also open to any other ways of accomplishing the same task.

I seems so simple a task, I thought it was just my VB rust getting in the way.

How would I go about doing a wildcard search for a filename then copying the file I found to another network location?

I don't appear to have access in my program to filesystemobjects or the methods for them, if that's the right terminology.

Thanks



K
Post #10058
Posted 3/30/2005 9:05:51 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 2/28/2006 11:41:01 AM
Posts: 48, Visits: 3

Add a reference to Microsoft Scripting Runtime.  You might also want to look into the API for finding your files as it is faster.  Here is an example using the FSO:

http://www.freevbcode.com/ShowCode.Asp?ID=5510



Swi
Post #10084
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Brian, Peter

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 5:58am