Private Sub Form_Load() Dim strPath As String strPath = "c:\autoexec.bat"
If FolderExists(strPath) = False And FileExists(strPath) = True Then MsgBox "Det er en file." ElseIf FolderExists(strPath) = True Or FileExists(strPath) = True Then MsgBox "Det er et bibliotek." ElseIf FolderExists(strPath) = False And FileExists(strPath) = False Then MsgBox "Stigen er ikke korrekt." End If End Sub '----------------------------------- Form1 -----------------------------------
Private Const MAX_PATH As Long = 260 Private Const INVALID_HANDLE_VALUE As Long = -1 Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type
Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14 End Type
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Public Function FileExists(ByVal strFiles As String) As Boolean Dim WFD As WIN32_FIND_DATA Dim hFile As Long hFile = FindFirstFile(strFiles, WFD) FileExists = CBool(hFile <> INVALID_HANDLE_VALUE) Call FindClose(hFile) End Function
Public Function FolderExists(ByVal strFolder As String) As Boolean Dim hFile As Long Dim WFD As WIN32_FIND_DATA strFolder = QualifyPath(strFolder) hFile = FindFirstFile(strFolder, WFD) FolderExists = CBool((hFile <> INVALID_HANDLE_VALUE) And _ (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY)) Call FindClose(hFile) End Function
Private Function QualifyPath(ByVal strFolder As String) As String strFolder = Trim$(strFolder) If Right$(strFolder, 1) = "\" Then QualifyPath = Left$(strFolder, Len(strFolder) - 1) Else: QualifyPath = strFolder End If End Function '---------------------------------- Module1 ----------------------------------
Private Sub Form_Load() Dim strPath As String Dim fso As Object strPath = "c:\autoexec.bat"
Set fso = CreateObject("Scripting.FileSystemObject")
With fso If .FolderExists(strPath) = False And .FileExists(strPath) = True Then MsgBox "Det er en file." ElseIf .FolderExists(strPath) = True Or .FileExists(strPath) = True Then MsgBox "Det er et bibliotek." ElseIf .FolderExists(strPath) = False And .FileExists(strPath) = False Then MsgBox "Stigen er ikke korrekt." End If End With
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.