Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > How can i check if a file exists


Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2002, 05:30 AM
Daniel
Guest
 
Posts: n/a
Angry How can i check if a file exists


I have to check if a file exist, caus when it don''t excists i have to un an other file, so what will be the code to check if a file excists
Reply With Quote
  #2  
Old 09-28-2002, 05:51 AM
RemoteHoax RemoteHoax is offline
Centurion
 
Join Date: Sep 2002
Location: Chandigarh
Posts: 143
Default

check the Dir function
__________________
Holla! If ya hear me!
Reply With Quote
  #3  
Old 09-28-2002, 05:56 AM
Daniel
Guest
 
Posts: n/a
Default

I can''t install MSDN, so i have no help function, so can u please tell me how to do it
Reply With Quote
  #4  
Old 09-28-2002, 07:21 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

The Dir$ function returns the filename given in the first parameter if it exists, otherwise it returns "".

So you can check like this:
Code:
Dim TestStr As String TestStr = Dir$("yourfilepath") If Len(TestStr) = 0 Then MsgBox "File Does not Exist." End If
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 09-28-2002, 12:09 PM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,884
Default

Why can't you install MSDN??

You also can use MSDN online on the Microsoft website.
Reply With Quote
  #6  
Old 09-28-2002, 12:13 PM
JDT JDT is offline
Original Contributor

Retired Moderator
* Guru *
 
Join Date: Jan 2001
Location: Watch Window
Posts: 2,781
Default

You could also use ArnoutV's favorite way, the FileSystemObject has a FileExists method.

j/k ArnoutV
__________________
JDT
Reply With Quote
  #7  
Old 09-28-2002, 01:05 PM
technomag technomag is offline
Newcomer
 
Join Date: Sep 2002
Posts: 23
Default

you can use the filesystem obgect:

Public Function FileFind(FileLocation As String) As Boolean
Dim fso As FileSystemObject

Set fso = New FileSystemObject
If fso.FileExists(FileLocation) Then
FileFind = True
Else
FileFind = False
End If
End Function

the FileLocation string shuld be the full path to the file like:
c:\my documents\file1.txt
Reply With Quote
  #8  
Old 09-28-2002, 01:24 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

ick :P
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #9  
Old 09-28-2002, 02:58 PM
Daniel
Guest
 
Posts: n/a
Default

Euhmm, i can''t MSDN because when it says locate the msdn disc, i put in the msdn disc, and it says it is the wrong disc. But anyway, u guys helped me out very much, it is working now
Reply With Quote
  #10  
Old 09-29-2002, 01:29 AM
Hasin's Avatar
Hasin Hasin is offline
Centurion
 
Join Date: Sep 2002
Location: Bangladesh
Posts: 118
Default

MSDN has a buh in it as I think - If you want to reinstall it it shows the message "Error creating collection and does not work. I see it in all of my friends. They guess it as a bug.
__________________
Hasin Hayder
http://www.vbsthopoti.cjb.net
Lead Programmer - EvelinDev
Things that are tough takes time - Things that are impossible takes a little more.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->