-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUtils.bas
More file actions
122 lines (113 loc) · 4.13 KB
/
FileUtils.bas
File metadata and controls
122 lines (113 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=StaticCode
Version=6
@EndOfDesignText@
#IgnoreWarnings:12
Sub Process_Globals
Private fx As JFX
End Sub
Public Sub openFolder(path As String)
If Utils.DetectOS = "mac" Then
Dim sh As Shell
sh.Initialize("sh","open",Array(path))
sh.Run(200)
Else
fx.ShowExternalDocument(path)
End If
End Sub
Sub createNonExistingDir(path As String)
path=File.GetFileParent(path)
Dim seperator As String=GetSystemProperty("file.separator","/")
path=path.Replace(seperator,CRLF)
Dim seperated As List
seperated.Initialize
seperated.addall(Regex.Split(CRLF,path))
Dim newPath As String
For Each item As String In seperated
newPath=newPath&item&seperator
If File.Exists(newPath,"")=False Then
File.MakeDir(newPath,"")
End If
Next
End Sub
'Similar to File.Copy() but also folders with content can be copied
Sub Copy(DirSource As String, FileSource As String, DirTarget As String, FileTarget As String)
If File.IsDirectory(DirSource, FileSource) Then
Dim sourcePath As String = File.Combine(DirSource, FileSource)
Dim targetPath As String = File.Combine(DirTarget, FileTarget)
Dim sourceFiles As List = File.ListFiles(sourcePath)
If sourceFiles.IsInitialized = False Then Return 'Return if folder is not accessible
File.MakeDir(DirTarget, FileTarget)
For Each name As String In sourceFiles
Copy(sourcePath, name, targetPath, name) '+26/06/18
Next
Else
File.Copy(DirSource, FileSource, DirTarget, FileTarget)
End If
End Sub
'Similar to File.CopyAsync() but also folders with content can be copied
Public Sub CopyAsync (DirSource As String, FileSource As String, DirTarget As String, FileTarget As String) As ResumableSub '+26/06/18
Dim innerSuccess As Boolean = True
Dim sourcePath As String = File.Combine(DirSource, FileSource)
Dim targetPath As String = File.Combine(DirTarget, FileTarget)
If File.IsDirectory(DirSource, FileSource) Then
Dim sourceFiles As List = File.ListFiles(sourcePath)
If sourceFiles.IsInitialized = False Then Return False 'Return false if folder is not accessible
File.MakeDir(DirTarget, FileTarget)
For Each name As String In sourceFiles
Dim obj As Object = CopyAsync(sourcePath, name, targetPath, name)
Wait For (obj) Complete (Success As Boolean)
innerSuccess = innerSuccess And Success
Next
Else
Dim obj1 As Object = File.CopyAsync(sourcePath, name, targetPath, name)
Wait For (obj1) Complete (Success As Boolean)
innerSuccess = innerSuccess And Success
End If
Return innerSuccess
End Sub
'Similar to File.Delete() but also folders with content can be deleted
Sub Delete(Folder As String, FileName As String)
If File.IsDirectory(Folder, FileName) Then
Dim completePath As String = File.Combine(Folder, FileName)
Dim files As List = File.ListFiles(completePath)
For Each name As String In files
If File.IsDirectory(completePath, name) Then
Delete(completePath, name)
End If
File.Delete(completePath, name)
Next
End If
File.Delete(Folder, FileName)
End Sub
Sub RenameTo(Folder As String, FileName As String, NewFileName As String) '+10/07/18
Dim fileJO As JavaObject
fileJO.InitializeNewInstance("java.io.File", Array(File.Combine(Folder, FileName)))
Dim newFileJO As JavaObject
newFileJO.InitializeNewInstance("java.io.File", Array(File.Combine(Folder, NewFileName)))
fileJO.RunMethod("renameTo", Array(newFileJO))
End Sub
'Return a list of all the paths of the subfolders in rootFolder.
'The list will not contain RootFolder
Sub GetSubFolders(RootFolder As String) As List
Dim subFolders As List
subFolders.Initialize
ExtractSubFolders(RootFolder, subFolders)
Return subFolders
End Sub
'Extract subfolders from RootFolder recursively.
'Subfolder paths will be added to SubFolders
'Sub Folders will not contain RootFolder
Private Sub ExtractSubFolders(RootFolder As String, SubFolders As List)
Dim tempList As List = File.ListFiles(RootFolder)
For i = 0 To tempList.Size-1
Dim watchedElement As String = tempList.Get(i)
If File.IsDirectory(RootFolder, watchedElement) Then
Dim newPath As String = File.Combine(RootFolder, watchedElement)
SubFolders.Add(newPath)
ExtractSubFolders(newPath,SubFolders)
End If
Next
End Sub