VCS_Dir.bas 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Option Compare Database
  2. Option Private Module
  3. Option Explicit
  4. ' Path/Directory of the current database file.
  5. Public Function ProjectPath() As String
  6. ProjectPath = CurrentProject.path
  7. If Right$(ProjectPath, 1) <> "\" Then ProjectPath = ProjectPath & "\"
  8. End Function
  9. ' Path/Directory for source files
  10. Public Function SourcePath() As String
  11. SourcePath = ProjectPath & CurrentProject.name & ".src\"
  12. End Function
  13. ' Create folder `Path`. Silently do nothing if it already exists.
  14. Public Sub MkDirIfNotExist(ByVal path As String)
  15. On Error GoTo MkDirIfNotexist_noop
  16. MkDir path
  17. logger "MkDirIfNotExist", "INFO", "New dir created: " & path
  18. MkDirIfNotexist_noop:
  19. On Error GoTo 0
  20. End Sub
  21. ' Delete a file if it exists.
  22. Public Sub DelIfExist(ByVal path As String)
  23. On Error GoTo DelIfNotExist_Noop
  24. Kill path
  25. logger "DelIfExist", "INFO", "Killed: " & path
  26. DelIfNotExist_Noop:
  27. On Error GoTo 0
  28. End Sub
  29. ' Erase all *.`ext` files in `Path`.
  30. Public Sub ClearTextFilesFromDir(ByVal path As String, ByVal Ext As String, Optional ByVal force As Boolean = False)
  31. '### 13/10/2016: add optimizer
  32. ' we don't want to clear the text files of the objects which will not be exported
  33. 'BUT we still want to clear obsolete files: see CleanDirs in optimizer
  34. If optimizer_activated() And Not force Then
  35. logger "ClearTextFilesFromDir", "INFO", "Optimizer on: sub aborted"
  36. Exit Sub
  37. End If
  38. '###
  39. logger "ClearTextFilesFromDir", "DEBUG", "Clear dir: " & path & "*." & Ext
  40. Dim fso As Object
  41. Set fso = CreateObject("Scripting.FileSystemObject")
  42. If Not fso.FolderExists(path) Then Exit Sub
  43. On Error GoTo ClearTextFilesFromDir_noop
  44. If dir$(path & "*." & Ext) <> vbNullString Then
  45. fso.DeleteFile path & "*." & Ext
  46. End If
  47. ClearTextFilesFromDir_noop:
  48. On Error GoTo 0
  49. End Sub
  50. Public Function DirExists(ByVal strPath As String) As Boolean
  51. On Error Resume Next
  52. DirExists = False
  53. DirExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
  54. End Function
  55. Public Function FileExists(ByVal strPath As String) As Boolean
  56. On Error Resume Next
  57. FileExists = False
  58. FileExists = ((GetAttr(strPath) And vbDirectory) <> vbDirectory)
  59. End Function