-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfilesystem.vbs
70 lines (60 loc) · 1.47 KB
/
filesystem.vbs
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
'
' Filesystem module
'
' Author: Jardel Weyrich <jardel@teltecsolutions.com.br>
'
Option Explicit
Function FolderExists(ByVal fullpath)
Dim ofs
Set ofs = WScript.CreateObject("Scripting.FileSystemObject")
FolderExists = ofs.FolderExists(fullpath)
Set ofs = Nothing
End Function
Function FileExists(ByVal fullpath)
Dim ofs
Set ofs = WScript.CreateObject("Scripting.FileSystemObject")
FileExists = ofs.FileExists(fullpath)
Set ofs = Nothing
End Function
Function CreateFolderRecursive(ByVal fullpath)
CreateFolderRecursive = True
Dim ofs
Set ofs = WScript.CreateObject("Scripting.FileSystemObject")
If ofs.FolderExists(fullpath) Then
Set ofs = Nothing
Exit Function
End If
Dim isUncPath: isUncPath = StartsWith(fullpath, "\\")
Dim parts
Dim path
If isUncPath Then
parts = Split(Mid(fullpath, 3), "\") ' Skip the initial "\\"
path = "\\" ' Start the path with "\\"
Else
parts = Split(fullpath, "\")
path = ""
End If
Dim dir
For Each dir In parts
If path <> "" And path <> "\\" Then path = path & "\"
If path <> "\\" Then
path = path & dir
On Error Resume Next
If Not ofs.FolderExists(path) Then
ofs.CreateFolder(path)
End If
If Err.Number <> 0 Then
LogError("Cannot access/create folder " & path)
Err.Clear
Set ofs = Nothing
CreateFolderRecursive = False
Exit Function
End If
On Error Goto 0
Else
path = path & dir
End If
'LogDebug("path=" & path & " dir=" & dir)
Next
Set ofs = Nothing
End Function