1 | Namespace System
|
---|
2 | Namespace IO
|
---|
3 |
|
---|
4 |
|
---|
5 | Class FileInfo
|
---|
6 | Inherits FileSystemInfo
|
---|
7 | Public
|
---|
8 | Sub FileInfo(path As String)
|
---|
9 | OriginalPath = path
|
---|
10 | FullPath = Path.GetFullPath(path)
|
---|
11 | End Sub
|
---|
12 |
|
---|
13 | Sub ~FileInfo()
|
---|
14 | End Sub
|
---|
15 |
|
---|
16 | '----------------------------------------------------------------
|
---|
17 | ' パブリック プロパティ
|
---|
18 | '----------------------------------------------------------------
|
---|
19 |
|
---|
20 | Function Directory() As DirectoryInfo
|
---|
21 | Return New DirectoryInfo(Path.GetDirectoryName(FullPath))
|
---|
22 | End Function
|
---|
23 |
|
---|
24 | Function DirectoryName() As String
|
---|
25 | Return Path.GetDirectoryName(FullPath)
|
---|
26 | End Function
|
---|
27 |
|
---|
28 | Function IsReadOnly() As Boolean
|
---|
29 | If (Attributes and FileAttributes.ReadOnly) = FileAttributes.ReadOnly Then
|
---|
30 | Return True
|
---|
31 | Else
|
---|
32 | Return False
|
---|
33 | End If
|
---|
34 | End Function
|
---|
35 |
|
---|
36 | Function Length() As QWord
|
---|
37 | Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
|
---|
38 | If hFile = INVALID_HANDLE_VALUE Then
|
---|
39 | Throw New IOException("FileInfo.Length: Failed to CreateFile.")
|
---|
40 | Exit Function
|
---|
41 | End If
|
---|
42 |
|
---|
43 | Dim length As QWord
|
---|
44 | If GetFileSizeEx(hFile, VarPtr(length)) Then
|
---|
45 | CloseHandle(hFile)
|
---|
46 | Return length
|
---|
47 | Else
|
---|
48 | CloseHandle(hFile)
|
---|
49 | Throw New IOException("FileInfo.Length: Failed to GetFileSize")
|
---|
50 | End If
|
---|
51 | End Function
|
---|
52 |
|
---|
53 | '----------------------------------------------------------------
|
---|
54 | ' パブリック メソッド
|
---|
55 | '----------------------------------------------------------------
|
---|
56 |
|
---|
57 | /* Function AppendText() As StreamWriter
|
---|
58 | End Function*/
|
---|
59 |
|
---|
60 | Function CopyTo(destFileName As String) As FileInfo
|
---|
61 | Return CopyTo(destFileName, False)
|
---|
62 | End Function
|
---|
63 |
|
---|
64 | Function CopyTo(destFileName As String, overwrite As Boolean) As FileInfo
|
---|
65 | File.Copy(FullPath, destFileName, overwrite)
|
---|
66 | Return New FileInfo(destFileName)
|
---|
67 | End Function
|
---|
68 |
|
---|
69 | Function Create() As FileStream
|
---|
70 | Return File.Create(FullPath)
|
---|
71 | End Function
|
---|
72 |
|
---|
73 | /* Function CreateText() As StreamWriter
|
---|
74 | End Function*/
|
---|
75 |
|
---|
76 | /* Sub Decrypt()
|
---|
77 | End Sub*/
|
---|
78 |
|
---|
79 | Override Sub Delete()
|
---|
80 | File.Delete(FullPath)
|
---|
81 | End Sub
|
---|
82 |
|
---|
83 | /* Sub Encrypt()
|
---|
84 | End Sub*/
|
---|
85 |
|
---|
86 | /* Function GetAccessControl() As FileSecurity
|
---|
87 | End Function*/
|
---|
88 |
|
---|
89 | /* Function GetAccessControl(includeSections As AccessControlSections) As FileScurity
|
---|
90 | End Function*/
|
---|
91 |
|
---|
92 | Sub MoveTo(destFileName As String)
|
---|
93 | File.Move(FullPath, destFileName)
|
---|
94 | End Sub
|
---|
95 |
|
---|
96 | Function Open(mode As FileMode) As FileStream
|
---|
97 | Return New FileStream(FullPath, mode)
|
---|
98 | End Function
|
---|
99 |
|
---|
100 | Function Open(mode As FileMode, access As FileAccess) As FileStream
|
---|
101 | Return New FileStream(FullPath, mode, access)
|
---|
102 | End Function
|
---|
103 |
|
---|
104 | Function Open(mode As FileMode, access As FileAccess, share As FileShare ) As FileStream
|
---|
105 | Return New FileStream(FullPath, mode, access, share)
|
---|
106 | End Function
|
---|
107 |
|
---|
108 | Function OpenRead() As FileStream
|
---|
109 | Return Open(FileMode.Open, FileAccess.Read, FileShare.Read)
|
---|
110 | End Function
|
---|
111 |
|
---|
112 | Function OpenText() As StreamReader
|
---|
113 | Return New StreamReader(FullPath)
|
---|
114 | End Function
|
---|
115 |
|
---|
116 | Function OpenWrite() As FileStream
|
---|
117 | Return Open(FileMode.Open, FileAccess.Write)
|
---|
118 | End Function
|
---|
119 |
|
---|
120 | /* Function Replace(destinationFileName As String, destinationBackupFileName As String) As FileInfo
|
---|
121 | End Function*/
|
---|
122 |
|
---|
123 | /* Function Replace(destinationFileName As String, destinationBackupFileName As String, ignoreMetadataErrors As Boolean) As FileInfo
|
---|
124 | End Function*/
|
---|
125 |
|
---|
126 | /* Sub SetAccessControl(fileSecurity As FileSecurity)
|
---|
127 | End Sub*/
|
---|
128 |
|
---|
129 | Override Function ToString() As String
|
---|
130 | Return FullPath
|
---|
131 | End Function
|
---|
132 |
|
---|
133 | End Class
|
---|
134 |
|
---|
135 |
|
---|
136 | End Namespace
|
---|
137 | End Namespace
|
---|