Results 1 to 11 of 11

Thread: File Exists (On NetWork)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Talking File Exists (On NetWork)

    how do I check to see if a file exists on the other end of a network?

    The file is

    \\Eduardo\c\WINNT\customerinfo.mdb

    and this code doesnt work:

    VB Code:
    1. Function FileExists(s As String) As Boolean
    2. If Dir(s) <> "" Then
    3.     FileExists = True
    4. Else
    5.     FileExists = False
    6. End If
    7. End Function
    Last edited by Evan; Dec 7th, 2001 at 01:55 PM.

  2. #2
    New Member
    Join Date
    Aug 2001
    Posts
    13

    Thumbs up

    Try this version of FileExists instead :

    MyCheck = FileExists("\\Eduardo\c\WINNT\customerinfo.mdb")



    Private Function FileExists(FullFileName As String) As Boolean
    On Error GoTo MakeF
    'If file does Not exist, there will be an Error
    Open FullFileName For Input As #1
    Close #1
    'no error, file exists
    DoExists = True
    Exit Function
    MakeF:
    'error, file does Not exist
    DoExists = False
    Exit Function
    End Function

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    TY!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Do you need to use the UNC name? I've found it much easier to temporarily map a drive to the server using an unused drive letter, do my check, then disconnect the drive. That way, I can use something like s:\WINNT\customerinfo.mdb

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    why not use the Dir() function?

    VB Code:
    1. MyCheck = FileExists("\\Eduardo\c\WINNT\customerinfo.mdb")
    2.  
    3. Private Function FileExists(FullFileName As String) As Boolean
    4. If len(Dir(FullFileName,vbNormal)) = 0 Then FileExsist = False Else FileExisit = True
    5. End Function

    if that file is LARGE then your app will slow down if the file does exsist. it will have to open it over the network, then just close it.

    this just checks the length of the file
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Originally posted by geoff_xrx
    why not use the Dir() function?

    VB Code:
    1. MyCheck = FileExists("\\Eduardo\c\WINNT\customerinfo.mdb")
    2.  
    3. Private Function FileExists(FullFileName As String) As Boolean
    4. If len(Dir(FullFileName,vbNormal)) = 0 Then FileExsist = False Else FileExisit = True
    5. End Function

    Thats what I was using. It wont work over the network.
    and yes, the other way does slow my program down.

    if that file is LARGE then your app will slow down if the file does exsist. it will have to open it over the network, then just close it.

    this just checks the length of the file

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    yo probably dont have the correct path...

    I tried it over my network. works fine

    but heres the kicker...the mapped drive is not as obvious a path...

    mine looked like \\ROC_S1\C\filename.txt

    but it was actually a folder

    \\ROC_S1\ROC_Share\filename.txt


    go into you "entire Network" find eduardo...then look for the folder containing the file
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Oh... I fixed it. This works!

    VB Code:
    1. Private Function FileExists(FullFileName As String) As Boolean
    2. On Error GoTo CheckError
    3. If Len(Dir(FullFileName, vbNormal)) = 0 Then
    4.     FileExsist = False
    5. Else
    6.     FileExisit = True
    7. End If
    8. Exit Function
    9. CheckError:
    10.     FileExists = False
    11. End Function

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    I know the file exists, but his computer isnt on.
    So I guess that drive has to exist.

  10. #10
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    lol!

    that would be very helpful!

    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    You would think a function called 'FileExists' Could work all the time... guess not...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width