AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2006 Andrea Tincani

AndreaVB Home | Forum | News | Code Database Home | Search Database | View Latest Codes
Submit your Code | Register | HOWTO Submit a File

Code Database » Files and Disks » Two functions to check if a folder exists and another to check if a folder is empty
File Info
Version : 1.0.0
Support Topic : Click Here (0 comments)
Demo : N/A
Screenshot : N/A
Post Date : Apr 11, 2005
Last Edit Date : Apr 11, 2005
Language Version : VB5, VB6
Current Rating : N/A
Author Info
Author Name : admin
Author Files Count : 8
% of Files by Author : 6.4516%
Private Msg : Login First!
Email : Login First!
Code Description
Two functions to check if a folder exists and another to check if a folder is empty
Download Info
Download File : Click to Download!
Total Downloads : 1650
FileSize: 1.11 KB
FileType: TXT file
User Feedback
Rate This Code :
VB Code
'this function returns true if the path exists, false if not
Public Function FolderExists(ByVal strPath As String) As Boolean
    Dim s As String
    
    'strip final slash from path
    If Right(strPath, 1) = "\" Then strPath = Left(strPath, Len(strPath) - 1)
    'check if directory exists
    s = Dir(strPath, vbDirectory)
    If s <> "" Then FolderExists = True
End Function

'this function returns true if the directory is empty:
'this means that the directory only contains "." and ".." system directories
Public Function IsFolderEmpty(ByVal strPath As String) As Boolean
    Dim s As String
    
    'add final slash from path
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
    'check directory contents (files and subfolders)
    s = Dir(strPath, vbNormal Or vbDirectory)
    IsFolderEmpty = True
    Do While s <> ""
        'if the directory contains something other than system folders
        'then it's not empty
        If s <> "." And s <> ".." Then
            IsFolderEmpty = False
            Exit Do
        End If
        'continue enum
        s = Dir
    Loop
End Function

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2006 Andrea Tincani

Powered by tForum version a0.93.9 (© 2002 Deathwalker)
This page required 0.0487179756165 seconds to parse.
This page required 10 queries to parse