Because FileCopy copies only files, here a first implementation of DirCopy, which copies complete directories:
|
Jabaco Source
|
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
|
Public Static Function DirCopy(Source As String, Destination As String) As Boolean
Dim SourceFile As java#io#File = New File(Source)
Dim DestinationFile As java#io#File = New File(Destination)
DirCopy = True
If (NOT SourceFile.exists) Then
MsgBox "Source-directory " & Chr(34) & Source & Chr(34) & " don't exists"
DirCopy = False
Exit Function
Elseif (NOT SourceFile.isDirectory) Then
MsgBox "Source-directory " & Chr(34) & Source & Chr(34) & " not a directory"
DirCopy = False
Exit Function
Else
If (NOT DestinationFile.exists) Then
MkDir Destination
End If
If (NOT DestinationFile.isDirectory) Then
MsgBox "Destination-directory " & Chr(34) & Destination & Chr(34) & " not a directory"
DirCopy = False
Exit Function
End If
End If
Dim childFolders() As File
childFolders() = SourceFile.listFiles()
Dim item As File
For Each item In childFolders
If item.isFile Then
FileCopy (Source & System.getProperty("file.separator") & item.getName , Destination & System.getProperty("file.separator") & item.getName)
ElseIf item.isDirectory Then
DirCopy (Source & System.getProperty("file.separator") & item.getName , Destination & System.getProperty("file.separator") & item.getName)
End If
Next
End Function
|
If I have more time and if I haven't forgotten it then, I will include it in the JabacoFramework.
Sadly the DirCopy works slow.
Currently I haven't checked, if the Destination-directory is a subdirectoy of the Source-directory. If so, then it copies endless.
So be careful, that the Source and the Destination are two complete different directories and not the one is included in the other.
Greatings
theuserbl