Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Exists (VB6)

    Having a little problem with my scripting routine.
    In my Archive folder, I have the ability to extract files as necessary.
    This routine is to check if a folder exists and if there are any files in it.
    If there are no files in the folder, I don't really want a prompt, but if files do exist, then yes a prompt is required.
    At the moment nothing happens at all when the function "FileExists()" is called.


    <pre> Dim fso As New scripting.FileSystemObject
    Dim fld As scripting.Folder
    Dim fil As scripting.File

    If FolderExists = fso.FolderExists("L:mmpdfArchive" & Me.txtEst) Then

    For Each fil In fld.Files
    If fld.Files.Count > 1 Then
    MsgBox fld.Files.Count
    Else
    End If
    Next fil
    End If

    Set fil = Nothing
    Set fld = Nothing
    Set fso = Nothing</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: File Exists (VB6)

    You never set fld in this code, so it remains Nothing.
    The condition If FolderExists = ... doesn't make sense, moreover FolderExists hasn't been declared as a variable.
    It doesn't make sense to loop through the files of a folder and count the files each time in the loop.
    If you want to test if a folder contains files, you should test for fld.Files.Count > 0, not > 1.

    Try this:
    <pre> Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.Folder
    Dim strPath As String

    strPath = "L:mmpdfArchive" & Me.txtEst
    If fso.FolderExists(strPath) Then
    Set fld = fso.GetFolder(strPath)
    If fld.Files.Count > 0 Then
    MsgBox fld.Files.Count
    End If
    End If

    Set fld = Nothing
    Set fso = Nothing
    </pre>

    The variable fil is not used here, so I omitted its declaration. The code uses GetFolder to set the fld variable.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Exists (VB6)

    Thanks Hans

    Have a great weekend.
    Hope it's better than ours, it's cold, wet, raining and dull.
    <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: File Exists (VB6)

    Here, it rained all day yesterday. It's dry now, but gray and cool. Probably some sun tomorrow.

    Have a good weekend.

Posting Permissions

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