1 | Class Path
|
---|
2 | Public
|
---|
3 | Static AltDirectorySeparatorChar = &H2F As Byte '/
|
---|
4 | Static DirectorySeparatorChar = &H5C As Byte '\
|
---|
5 | Static PathSeparator = &H3B As Byte ';
|
---|
6 | Static VolumeSeparatorChar = &H3A As Byte ':
|
---|
7 |
|
---|
8 | Static Function GetFileName(path As String) As String
|
---|
9 | path.Remove(0, getLastSeparatorPosision(path) + 1)
|
---|
10 | Return path
|
---|
11 | End Function
|
---|
12 |
|
---|
13 | Static Function GetFileNameWithoutExtension(path As String) As String
|
---|
14 | Dim fileName As String
|
---|
15 | Dim extPos As Long
|
---|
16 |
|
---|
17 | fileName = GetFileName(path)
|
---|
18 | extPos = getExtensionPosition(fileName)
|
---|
19 | If extPos = -1 Then Return ""
|
---|
20 |
|
---|
21 | fileName.Remove(extPos)
|
---|
22 | Return fileName
|
---|
23 | End Function
|
---|
24 |
|
---|
25 | '手抜き
|
---|
26 | Static Function GetRandomFileName() As String
|
---|
27 | Randomize
|
---|
28 | Dim temp As Long
|
---|
29 | temp = Rnd() * 900000000 + 10000000
|
---|
30 | Return Str$(temp)
|
---|
31 | End Function
|
---|
32 |
|
---|
33 | Static Function GetExtension(path As String) As String
|
---|
34 | Dim extPos As Long
|
---|
35 | extPos = getExtensionPosition(path)
|
---|
36 | If extPos = -1 Then Return ""
|
---|
37 |
|
---|
38 | path.Remove(0, extPos)
|
---|
39 | Return path
|
---|
40 | End Function
|
---|
41 |
|
---|
42 | Static Function ChangeExtension(path As String, extension As String) As String
|
---|
43 | Dim extPos As Long
|
---|
44 | extPos = getExtensionPosition(path)
|
---|
45 | If extPos => 0 Then
|
---|
46 | path.Remove(extPos)
|
---|
47 | End If
|
---|
48 |
|
---|
49 | Return path + extension
|
---|
50 | End Function
|
---|
51 |
|
---|
52 | Static Function HasExtension(ByRef path As String) As BOOL
|
---|
53 | If GetExtension(path) <> "" Then
|
---|
54 | Return _System_TRUE
|
---|
55 | Else
|
---|
56 | Return _System_FALSE
|
---|
57 | End If
|
---|
58 | End Function
|
---|
59 |
|
---|
60 | Static Function GetTempFileName() As String
|
---|
61 | ' TODO: 実装
|
---|
62 | End Function
|
---|
63 |
|
---|
64 | Static Function GetTempPath() As String
|
---|
65 | GetTempPath.ReSize(__GetTempPath(0, 0) - 1)
|
---|
66 | __GetTempPath(GetTempPath.Length + 1, GetTempPath)
|
---|
67 | End Function
|
---|
68 |
|
---|
69 | Static Function GetFullPath(path As String) As String
|
---|
70 | Dim cd As String
|
---|
71 | cd.ReSize = GetCurrentDirectory(0, 0) - 1
|
---|
72 | GetCurrentDirectory(cd.Length + 1, cd)
|
---|
73 |
|
---|
74 | Dim dirSepChar As String(Chr$(DirectorySeparatorChar))
|
---|
75 | Return cd + dirSepChar + path
|
---|
76 | End Function
|
---|
77 |
|
---|
78 | Static Function GetDirectoryName(path As String) As String
|
---|
79 | Dim lastSepPos As Long
|
---|
80 | lastSepPos = getLastSeparatorPosision(path)
|
---|
81 | If lastSepPos = -1 Then Return ""
|
---|
82 |
|
---|
83 | path.Remove(lastSepPos)
|
---|
84 | If path.Length <= 3 Then
|
---|
85 | If IsPathRooted(path) Then Return ""
|
---|
86 | End If
|
---|
87 | Return path
|
---|
88 | End Function
|
---|
89 |
|
---|
90 | Static Function GetPathRoot(path As String) As String
|
---|
91 | If IsPathRooted(path) Then
|
---|
92 | path.Remove(3)
|
---|
93 | Return path
|
---|
94 | Else
|
---|
95 | Return ""
|
---|
96 | End If
|
---|
97 | End Function
|
---|
98 |
|
---|
99 | Static Function IsPathRooted(path As String) As BOOL
|
---|
100 | Dim volSepChar As String(Chr$(VolumeSeparatorChar))
|
---|
101 | If path.IndexOf(volSepChar, 1, 1) = 1 Then
|
---|
102 | Return _System_TRUE
|
---|
103 | Else
|
---|
104 | Return _System_FALSE
|
---|
105 | End If
|
---|
106 | End Function
|
---|
107 |
|
---|
108 | Static Function Combine(path1 As String, path2 As String) As String
|
---|
109 | Dim volSepChar As String(Chr$(VolumeSeparatorChar))
|
---|
110 | Dim dirSepChar As String(Chr$(DirectorySeparatorChar))
|
---|
111 | If path1.LastIndexOf(volSepChar) And path1.Length = 2 Then
|
---|
112 | Return path1 + path2
|
---|
113 | End If
|
---|
114 |
|
---|
115 | If path1.LastIndexOf(dirSepChar, ELM(path1.Length), 1) = -1 Then
|
---|
116 | Return path1 + dirSepChar + path2
|
---|
117 | Else
|
---|
118 | Return path1 + path2
|
---|
119 | End If
|
---|
120 | End Function
|
---|
121 |
|
---|
122 | Private
|
---|
123 | Static Function getExtensionPosition(ByRef path As String) As Long
|
---|
124 | Dim lastSepPos As Long
|
---|
125 | lastSepPos = getLastSeparatorPosision(path)
|
---|
126 | getExtensionPosition = path.LastIndexOf(".", ELM(path.Length), path.Length - lastSepPos)
|
---|
127 | End Function
|
---|
128 |
|
---|
129 | Static Function getLastSeparatorPosision(ByRef path As String) As Long
|
---|
130 | Dim dirSepChar As String(Chr$(DirectorySeparatorChar))
|
---|
131 | Dim lastSepPos As Long
|
---|
132 | lastSepPos = path.LastIndexOf(dirSepChar)
|
---|
133 |
|
---|
134 | If lastSepPos = -1 Then
|
---|
135 | Dim volSepChar As String(Chr$(VolumeSeparatorChar))
|
---|
136 | lastSepPos = path.LastIndexOf(volSepChar)
|
---|
137 | End If
|
---|
138 | Return lastSepPos
|
---|
139 | End Function
|
---|
140 | End Class
|
---|
141 |
|
---|
142 | '今はメソッド内で使えないので、実装されるまで回避
|
---|
143 | Function __GetTempPath(nBufferLength As DWord, lpBuffer As LPSTR) As DWord
|
---|
144 | Return GetTempPath(nBufferLength, lpBuffer)
|
---|
145 | End Function
|
---|