Solved

check file exist

Posted on 2006-06-30
2
255 Views
Last Modified: 2012-05-05
Hi,
 How to check if file Exist (VB6) ?

Thanks
0
Comment
Question by:madmare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17017424
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\Test.js") Then
  MsgBox "Exists"
End If
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17017480
Function FileExists(FileName As String) As Boolean
    On Error GoTo ErrorHandler
    ' get the attributes and ensure that it isn't a directory
    FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
    ' if an error occurs, this function returns False
End Function

 OR another way

 Function FileExist(sTestFile As String) As Boolean
    Dim lSize As Long
    On Error Resume Next
    'Preset length to -1 because files can be zero bytes in length
    lSize = -1
    'Get the length of the file
    lSize = FileLen(sTestFile)
    If lSize > -1 Then
        FileExist = True
    Else
        FileExist = False
    End If
End Function
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question