1 |
|
---|
2 | Namespace System
|
---|
3 | Namespace IO
|
---|
4 |
|
---|
5 | Class DirectoryInfo
|
---|
6 | Inherits FileSystemInfo
|
---|
7 | Public
|
---|
8 | Sub DirectoryInfo(path As String)
|
---|
9 | OriginalPath = path
|
---|
10 | FullPath = Path.GetFullPath(path)
|
---|
11 | Refresh()
|
---|
12 | End Sub
|
---|
13 |
|
---|
14 | Sub ~DirectoryInfo()
|
---|
15 | End Sub
|
---|
16 |
|
---|
17 | 'Public Property
|
---|
18 | Function Parent() As DirectoryInfo
|
---|
19 | Dim dirInfo As DirectoryInfo(Path.GetDirectoryName(FullPath))
|
---|
20 | Return dirInfo
|
---|
21 | End Function
|
---|
22 |
|
---|
23 | Function Root() As DirectoryInfo
|
---|
24 | Dim dirInfo As DirectoryInfo(Path.GetPathRoot(FullPath))
|
---|
25 | Return dirInfo
|
---|
26 | End Function
|
---|
27 |
|
---|
28 | 'Public Method
|
---|
29 | Sub Create()
|
---|
30 | CreateDirectory(ToTCStr(FullPath), NULL)
|
---|
31 | End Sub
|
---|
32 |
|
---|
33 | /* Sub Create(directorySecurity As DirectorySecurity)
|
---|
34 | End Sub*/
|
---|
35 |
|
---|
36 | Override Sub Delete()
|
---|
37 | RemoveDirectory(ToTCStr(FullPath))
|
---|
38 | End Sub
|
---|
39 |
|
---|
40 | Sub Delete(recursive As Boolean)
|
---|
41 | If recursive Then
|
---|
42 | ' ディレクトリ内のすべての情報を削除する
|
---|
43 |
|
---|
44 | Dim dirPath = FullPath As String
|
---|
45 |
|
---|
46 | ' 終端の '\' を除去
|
---|
47 | If dirPath[dirPath.Length-1] = Asc("\\") Then
|
---|
48 | dirPath = dirPath.SubString(0, dirPath.Length-1)
|
---|
49 | End If
|
---|
50 |
|
---|
51 | ' double null-terminated にする
|
---|
52 | dirPath = dirPath + Chr$(0)
|
---|
53 |
|
---|
54 | Dim op As SHFILEOPSTRUCT
|
---|
55 | op.hwnd = NULL
|
---|
56 | op.wFunc = FO_DELETE
|
---|
57 | op.pFrom = dirPath.Chars
|
---|
58 | op.pTo = NULL
|
---|
59 | op.fFlags = FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_SILENT
|
---|
60 |
|
---|
61 | If SHFileOperation(op) <> 0 Then
|
---|
62 | ' TODO: エラー処理
|
---|
63 | debug
|
---|
64 | End If
|
---|
65 | Else
|
---|
66 | ' ディレクトリが空の場合は削除する
|
---|
67 | This.Delete()
|
---|
68 | End If
|
---|
69 | End Sub
|
---|
70 |
|
---|
71 | /* Function GetAccessControl() As DirectorySecurity
|
---|
72 | End Function*/
|
---|
73 |
|
---|
74 | /* Function GetAccessControl(includeSections As AccessControlSections) As DirectorySecurity
|
---|
75 | End Function*/
|
---|
76 |
|
---|
77 | /* Function GetDirectories() As Array
|
---|
78 | End Function*/
|
---|
79 |
|
---|
80 | /* Function GetDirectories(searchPattern As String) As Array
|
---|
81 | End Function*/
|
---|
82 |
|
---|
83 | /* Function GetDirectories(searchPattern As String, searchOption As SearchOption) As Array
|
---|
84 | End Function*/
|
---|
85 |
|
---|
86 | /* Function GetFiles() As Array
|
---|
87 | End Function*/
|
---|
88 |
|
---|
89 | /* Function GetFiles(searchPattern As String) As Array
|
---|
90 | End Function*/
|
---|
91 |
|
---|
92 | /* Function GetFiles(searchPattern As String, searchOption As SearchOption) As Array
|
---|
93 | End Function*/
|
---|
94 |
|
---|
95 | /* Function GetFileSystemInfos() As Array
|
---|
96 | End Function*/
|
---|
97 |
|
---|
98 | /* Function GetFileSystemInfos(searchPattern As String) As Array
|
---|
99 | End Function*/
|
---|
100 |
|
---|
101 | Sub MoveTo(destDirName As String)
|
---|
102 | If MoveFile(ToTCStr(FullPath), ToTCStr(destDirName)) = FALSE Then
|
---|
103 | 'Exception
|
---|
104 | End If
|
---|
105 | End Sub
|
---|
106 |
|
---|
107 | /* Sub SetAccessControl(directorySecurity As DirectorySecurity)
|
---|
108 | End Sub*/
|
---|
109 |
|
---|
110 | End Class
|
---|
111 |
|
---|
112 | Enum SearchOption
|
---|
113 | AllDirectories
|
---|
114 | TopDirectoryOnly
|
---|
115 | End Enum
|
---|
116 |
|
---|
117 | End Namespace
|
---|
118 | End Namespace
|
---|