VCS_Dir.bas 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. MkDirIfNotexist_noop:
  18. On Error GoTo 0
  19. End Sub
  20. ' Delete a file if it exists.
  21. Public Sub DelIfExist(ByVal Path As String)
  22. On Error GoTo DelIfNotExist_Noop
  23. Kill Path
  24. DelIfNotExist_Noop:
  25. On Error GoTo 0
  26. End Sub
  27. ' Erase all *.`ext` files in `Path`.
  28. Public Sub ClearTextFilesFromDir(ByVal Path As String, ByVal Ext As String, Optional ByVal force As Boolean = False)
  29. '### 13/10/2016: add optimizer
  30. ' we don't want to clear the text files of the objects which will not be exported
  31. 'BUT we still want to clear obsolete files: see CleanDirs in optimizer
  32. If optimizer_activated() And Not force Then
  33. Exit Sub
  34. End If
  35. '###
  36. Dim fso As Object
  37. Set fso = CreateObject("Scripting.FileSystemObject")
  38. If Not fso.FolderExists(Path) Then Exit Sub
  39. On Error GoTo ClearTextFilesFromDir_noop
  40. If dir$(Path & "*." & Ext) <> vbNullString Then
  41. fso.DeleteFile Path & "*." & Ext
  42. End If
  43. ClearTextFilesFromDir_noop:
  44. On Error GoTo 0
  45. End Sub
  46. Public Function DirExists(ByVal strPath As String) As Boolean
  47. On Error Resume Next
  48. DirExists = False
  49. DirExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
  50. End Function
  51. Public Function FileExists(ByVal strPath As String) As Boolean
  52. On Error Resume Next
  53. FileExists = False
  54. FileExists = ((GetAttr(strPath) And vbDirectory) <> vbDirectory)
  55. End Function