VCS_Dir.bas 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Option Compare Database
  2. Option Private Module
  3. Option Explicit
  4. Private Declare Function PathIsRelative Lib "Shlwapi" _
  5. Alias "PathIsRelativeA" (ByVal path As String) As Long
  6. Public Enum EMakeDirStatus
  7. ErrSuccess = 0
  8. ErrRelativePath
  9. ErrInvalidPathSpecification
  10. ErrDirectoryCreateError
  11. ErrSpecIsFileName
  12. ErrInvalidCharactersInPath
  13. End Enum
  14. Const MAX_PATH = 260
  15. ' Create folder `Path`. Silently do nothing if it already exists.
  16. Public Sub MkDirIfNotExist(ByVal path As String)
  17. On Error GoTo MkDirIfNotexist_noop
  18. MkDir path
  19. logger "MkDirIfNotExist", "INFO", "New dir created: " & path
  20. MkDirIfNotexist_noop:
  21. On Error GoTo 0
  22. End Sub
  23. ' Delete a file if it exists.
  24. Public Sub DelIfExist(ByVal path As String)
  25. On Error GoTo DelIfNotExist_Noop
  26. Kill path
  27. 'logger "DelIfExist", "DEBUG", "Killed: " & path
  28. DelIfNotExist_Noop:
  29. On Error GoTo 0
  30. End Sub
  31. Public Function DirExists(ByVal strPath As String) As Boolean
  32. On Error Resume Next
  33. DirExists = False
  34. DirExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
  35. End Function
  36. Public Function FileExists(ByVal strPath As String) As Boolean
  37. On Error Resume Next
  38. FileExists = False
  39. FileExists = ((GetAttr(strPath) And vbDirectory) <> vbDirectory)
  40. End Function