Class Path Public Static AltDirectorySeparatorChar = &H2F As Byte '/ Static DirectorySeparatorChar = &H5C As Byte '\ Static PathSeparator = &H3B As Byte '; Static VolumeSeparatorChar = &H3A As Byte ': Static Function GetFileName(path As String) As String path.Remove(0, getLastSeparatorPosision(path) + 1) Return path End Function Static Function GetFileNameWithoutExtension(path As String) As String Dim fileName As String Dim extPos As Long fileName = GetFileName(path) extPos = getExtensionPosition(fileName) If extPos = -1 Then Return "" fileName.Remove(extPos) Return fileName End Function '手抜き Static Function GetRandomFileName() As String Randomize Dim temp As Long temp = Rnd() * 900000000 + 10000000 Return Str$(temp) End Function Static Function GetExtension(path As String) As String Dim extPos As Long extPos = getExtensionPosition(path) If extPos = -1 Then Return "" path.Remove(0, extPos) Return path End Function Static Function ChangeExtension(path As String, extension As String) As String Dim extPos As Long extPos = getExtensionPosition(path) If extPos => 0 Then path.Remove(extPos) End If Return path + extension End Function Static Function HasExtension(ByRef path As String) As BOOL If GetExtension(path) <> "" Then Return _System_TRUE Else Return _System_FALSE End If End Function Static Function GetTempFileName() As String ' TODO: 実装 End Function Static Function GetTempPath() As String GetTempPath.ReSize(__GetTempPath(0, 0) - 1) __GetTempPath(GetTempPath.Length + 1, GetTempPath) End Function Static Function GetFullPath(path As String) As String Dim cd As String cd.ReSize = GetCurrentDirectory(0, 0) - 1 GetCurrentDirectory(cd.Length + 1, cd) Dim dirSepChar As String(Chr$(DirectorySeparatorChar)) Return cd + dirSepChar + path End Function Static Function GetDirectoryName(path As String) As String Dim lastSepPos As Long lastSepPos = getLastSeparatorPosision(path) If lastSepPos = -1 Then Return "" path.Remove(lastSepPos) If path.Length <= 3 Then If IsPathRooted(path) Then Return "" End If Return path End Function Static Function GetPathRoot(path As String) As String If IsPathRooted(path) Then path.Remove(3) Return path Else Return "" End If End Function Static Function IsPathRooted(path As String) As BOOL Dim volSepChar As String(Chr$(VolumeSeparatorChar)) If path.IndexOf(volSepChar, 1, 1) = 1 Then Return _System_TRUE Else Return _System_FALSE End If End Function Static Function Combine(path1 As String, path2 As String) As String Dim volSepChar As String(Chr$(VolumeSeparatorChar)) Dim dirSepChar As String(Chr$(DirectorySeparatorChar)) If path1.LastIndexOf(volSepChar) And path1.Length = 2 Then Return path1 + path2 End If If path1.LastIndexOf(dirSepChar, ELM(path1.Length), 1) = -1 Then Return path1 + dirSepChar + path2 Else Return path1 + path2 End If End Function Private Static Function getExtensionPosition(ByRef path As String) As Long Dim lastSepPos As Long lastSepPos = getLastSeparatorPosision(path) getExtensionPosition = path.LastIndexOf(".", ELM(path.Length), path.Length - lastSepPos) End Function Static Function getLastSeparatorPosision(ByRef path As String) As Long Dim dirSepChar As String(Chr$(DirectorySeparatorChar)) Dim lastSepPos As Long lastSepPos = path.LastIndexOf(dirSepChar) If lastSepPos = -1 Then Dim volSepChar As String(Chr$(VolumeSeparatorChar)) lastSepPos = path.LastIndexOf(volSepChar) End If Return lastSepPos End Function End Class '今はメソッド内で使えないので、実装されるまで回避 Function __GetTempPath(nBufferLength As DWord, lpBuffer As LPSTR) As DWord Return GetTempPath(nBufferLength, lpBuffer) End Function