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!

Search a File in C:\ using VB6 1

Status
Not open for further replies.

plopez

Technical User
Apr 2, 2002
66
CL
Hi,my question is how can I find a file in C:\ using VB6 code?

Any ideas?...

thnkxs

 
Search this forum for FileSystemObject or FSO. That will help do it.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 

.... or place a FileListBox on your Form and
Code:
Private Sub Form_Load()
File1.Path = "C:\"
End Sub

It will show you files on C:\


Have fun.

---- Andy
 
Create a reference to Microsoft Scripting Runtime

(not tested but close)

Then:

Dim FSO As FileSystemObject
Dim fs, f, f1, filelist()
Set FSO = New FileSystemObject

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists("c:\YourFolder") Then
Msgbox "Found It"
else
MsgBox "Not There"
End If

or

If FSO.FileExists("c:\YourFile") Then
Msgbox "Found It"
else
MsgBox "Not There"
End If

Take a look here:

 
On a Form;

Private Sub Command1_Click()

a$ = Dir$("c:\*.*")

While Len(a$)
Print a$
a$ = Dir$
Wend

End Sub
 
>Dim fs, f, f1, filelist()

Hardly an example of strong typing. However, it also looks superfluous, since none of the values are being used anywhere. I suggest that this line be removed.
 
That's true...I got it from a website a couple of years ago and pasted it in verbatum. I never really paid attention to it until the "yuck" comment. I realize it's not a good coding standard.

Also, I know VB 6 defaults to varient for the first two variables. VB .Net doesn't do that so where in VB 6 this:

Dim X, Y, Z as long

Would mean only Z is long. In VB .Net all three would be long.

Thanks!
 
Well, not if it's got:
Dim FSO As FileSystemObject

What it really looks like is a horrible mishmash, cut-and-pasted together. TysonLPrice, I suggest you don't get any more code from the site you lifted this from ...

And further to my 'yuck', it doesn't need both of these lines either:

Set FSO = New FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")
 
Yes, I see that now.

Also, the examples in the posted link do mention that it can be used alternatively

>I suggest you don't get any more code from the site you lifted this from ...

Just to rule out a possible misunderstanding from other readers: it doesn't look like it came the from the page in the link posted by TysonLPrice, so they must be referring to a different page or site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top