' System/IO/Path.ab #require Class Path Public Static AltDirectorySeparatorChar = &H2F As Char '/ Static DirectorySeparatorChar = &H5C As Char '\ Static PathSeparator = &H3B As Char '; Static VolumeSeparatorChar = &H3A As Char ': Static Function GetFileName(path As String) As String Return path.Remove(0, getLastSeparatorPosision(path) + 1) 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 "" Return fileName.Remove(extPos) 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 "" Return path.Remove(0, extPos) 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 = path.Remove(extPos) End If Return path + extension End Function Static Function HasExtension(ByRef path As String) As Boolean If GetExtension(path) <> "" Then Return True Else Return False End If End Function Static Function GetTempFileName() As String Dim tempPathSize = __GetTempPath(0, 0) Dim tempPath = _System_malloc(SizeOf (TCHAR) * tempPathSize) As PTSTR If tempPath = 0 Then ' Throw OutOfMemoryException Debug End If If __GetTempPath(tempPathSize, tempPath) > tempPathSize Then ' Throw IOException? Debug End If Dim tempFileName[ELM(MAX_PATH)] As TCHAR __GetTempFileName(tempPath, "ABT", 0, tempFileName) free(tempPath) Return tempFileName End Function Static Function GetTempPath() As String Dim size = GetTempPath(0, 0 Dim tempPath = _System_malloc(size)) __GetTempPath(size, tempPath) GetTempPath = tempPath _System_free(tempPath) End Function Static Function GetFullPath(path As String) As String If IsPathRooted(path) Then Return path Else Return Environment.CurrentDirectory + Chr$(DirectorySeparatorChar) + path End If End Function Static Function GetDirectoryName(path As String) As String Dim lastSepPos As Long lastSepPos = getLastSeparatorPosision(path) If lastSepPos = -1 Then Return "" path = 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 Return path.Remove(3) Else Return "" End If End Function Static Function IsPathRooted(path As String) As Boolean Dim volSepChar As String(Chr$(VolumeSeparatorChar)) If path.IndexOf(volSepChar, 1, 1) = 1 Then Return True Else Return 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 lastSepPos As Long Dim dirSepChar As String(Chr$(DirectorySeparatorChar)) Dim volSepChar As String(Chr$(VolumeSeparatorChar)) lastSepPos = path.LastIndexOf(dirSepChar) If lastSepPos <> -1 Then Return lastSepPos lastSepPos = path.LastIndexOf(dirSepChar) If lastSepPos <> -1 Then Return lastSepPos lastSepPos = path.LastIndexOf(volSepChar) Return lastSepPos End Function End Class '今はメソッド内で使えないので、実装されるまで回避 Function __GetTempPath(nBufferLength As DWord, lpBuffer As LPSTR) As DWord Return GetTempPath(nBufferLength, lpBuffer) End Function Function __GetTempFileName(pPathName As PCSTR, pPrefixString As PCSTR, uUnique As DWord, pTempFileName As PSTR) As DWord Return GetTempFileName(pPathName, pPrefixString, uUnique, pTempFileName) End Function