[61] | 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
|
---|
[62] | 71 | Dim dirSepChar As String(Chr$(DirectorySeparatorChar))
|
---|
| 72 | If IsPathRooted(path) Then Return path
|
---|
| 73 |
|
---|
[61] | 74 | cd.ReSize = GetCurrentDirectory(0, 0) - 1
|
---|
| 75 | GetCurrentDirectory(cd.Length + 1, cd)
|
---|
| 76 | Return cd + dirSepChar + path
|
---|
| 77 | End Function
|
---|
| 78 |
|
---|
| 79 | Static Function GetDirectoryName(path As String) As String
|
---|
| 80 | Dim lastSepPos As Long
|
---|
| 81 | lastSepPos = getLastSeparatorPosision(path)
|
---|
| 82 | If lastSepPos = -1 Then Return ""
|
---|
| 83 |
|
---|
| 84 | path.Remove(lastSepPos)
|
---|
| 85 | If path.Length <= 3 Then
|
---|
| 86 | If IsPathRooted(path) Then Return ""
|
---|
| 87 | End If
|
---|
| 88 | Return path
|
---|
| 89 | End Function
|
---|
| 90 |
|
---|
| 91 | Static Function GetPathRoot(path As String) As String
|
---|
| 92 | If IsPathRooted(path) Then
|
---|
| 93 | path.Remove(3)
|
---|
| 94 | Return path
|
---|
| 95 | Else
|
---|
| 96 | Return ""
|
---|
| 97 | End If
|
---|
| 98 | End Function
|
---|
| 99 |
|
---|
| 100 | Static Function IsPathRooted(path As String) As BOOL
|
---|
| 101 | Dim volSepChar As String(Chr$(VolumeSeparatorChar))
|
---|
| 102 | If path.IndexOf(volSepChar, 1, 1) = 1 Then
|
---|
| 103 | Return _System_TRUE
|
---|
| 104 | Else
|
---|
| 105 | Return _System_FALSE
|
---|
| 106 | End If
|
---|
| 107 | End Function
|
---|
| 108 |
|
---|
| 109 | Static Function Combine(path1 As String, path2 As String) As String
|
---|
| 110 | Dim volSepChar As String(Chr$(VolumeSeparatorChar))
|
---|
| 111 | Dim dirSepChar As String(Chr$(DirectorySeparatorChar))
|
---|
| 112 | If path1.LastIndexOf(volSepChar) And path1.Length = 2 Then
|
---|
| 113 | Return path1 + path2
|
---|
| 114 | End If
|
---|
| 115 |
|
---|
| 116 | If path1.LastIndexOf(dirSepChar, ELM(path1.Length), 1) = -1 Then
|
---|
| 117 | Return path1 + dirSepChar + path2
|
---|
| 118 | Else
|
---|
| 119 | Return path1 + path2
|
---|
| 120 | End If
|
---|
| 121 | End Function
|
---|
| 122 |
|
---|
| 123 | Private
|
---|
| 124 | Static Function getExtensionPosition(ByRef path As String) As Long
|
---|
| 125 | Dim lastSepPos As Long
|
---|
| 126 | lastSepPos = getLastSeparatorPosision(path)
|
---|
| 127 | getExtensionPosition = path.LastIndexOf(".", ELM(path.Length), path.Length - lastSepPos)
|
---|
| 128 | End Function
|
---|
| 129 |
|
---|
| 130 | Static Function getLastSeparatorPosision(ByRef path As String) As Long
|
---|
[62] | 131 | Dim lastSepPos As Long
|
---|
[61] | 132 | Dim dirSepChar As String(Chr$(DirectorySeparatorChar))
|
---|
[62] | 133 | Dim altDirSepChar As String(Chr$(AltDirectorySeparatorChar))
|
---|
| 134 | Dim volSepChar As String(Chr$(VolumeSeparatorChar))
|
---|
[61] | 135 | lastSepPos = path.LastIndexOf(dirSepChar)
|
---|
[62] | 136 | If lastSepPos <> -1 Then Return lastSepPos
|
---|
[61] | 137 |
|
---|
[62] | 138 | lastSepPos = path.LastIndexOf(dirSepChar)
|
---|
| 139 | If lastSepPos <> -1 Then Return lastSepPos
|
---|
| 140 |
|
---|
| 141 | lastSepPos = path.LastIndexOf(volSepChar)
|
---|
[61] | 142 | Return lastSepPos
|
---|
| 143 | End Function
|
---|
| 144 | End Class
|
---|
| 145 |
|
---|
| 146 | '今はメソッド内で使えないので、実装されるまで回避
|
---|
| 147 | Function __GetTempPath(nBufferLength As DWord, lpBuffer As LPSTR) As DWord
|
---|
| 148 | Return GetTempPath(nBufferLength, lpBuffer)
|
---|
| 149 | End Function
|
---|