Changeset 404


Ignore:
Timestamp:
Feb 12, 2008, 3:40:11 PM (16 years ago)
Author:
OverTaker
Message:

地味に修整

Location:
trunk/Include/Classes/System/IO
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/System/IO/DirectoryInfo.ab

    r376 r404  
    77    Inherits FileSystemInfo
    88Public
     9    /*!
     10    @brief  コンストラクタ
     11    @author OverTaker
     12    @date   2007/11/11
     13    @param  ディレクトリのパス
     14    */
    915    Sub DirectoryInfo(path As String)
    1016        OriginalPath = path
     
    1521    End Sub
    1622
    17     'Public Property
     23    '----------------------------------------------------------------
     24    ' パブリック プロパティ
     25    '----------------------------------------------------------------
     26
     27    /*!
     28    @brief  ひとつ上のディレクトリを取得する
     29    @author OverTaker
     30    @date   2007/11/11
     31    @return 親ディレクトリ
     32    */
    1833    Function Parent() As DirectoryInfo
    1934        Return New DirectoryInfo(Path.GetDirectoryName(FullPath))
    2035    End Function
    2136
     37    /*!
     38    @brief  ルートディレクトリを取得する
     39    @author OverTaker
     40    @date   2007/11/11
     41    @return ルートディレクトリ
     42    */
    2243    Function Root() As DirectoryInfo
    2344        Return New DirectoryInfo(Path.GetPathRoot(FullPath))
    2445    End Function
    2546
    26     'Public Method
     47    '----------------------------------------------------------------
     48    ' パブリック メソッド
     49    '----------------------------------------------------------------
     50
     51    /*!
     52    @brief  ディレクトリを作成する
     53    @author OverTaker
     54    @date   2007/11/11
     55    */
    2756    Sub Create()
    2857        CreateDirectory(ToTCStr(FullPath), NULL)
     
    3261    End Sub*/
    3362
     63    /*!
     64    @brief  ディレクトリを削除する。ただしディレクトリが空の場合
     65    @author OverTaker
     66    @date   2007/11/11
     67    */
    3468    Override Sub Delete()
    3569        RemoveDirectory(ToTCStr(FullPath))
    3670    End Sub
    3771
     72    /*!
     73    @brief  ディレクトリを削除する
     74    @author OverTaker
     75    @date   2007/11/11
     76    @param  ディレクトリのファイルごと消すかどうか
     77    */
    3878    Sub Delete(recursive As Boolean)
    3979        If recursive Then
     
    73113    End Function*/
    74114
     115    /*!
     116    @brief  ディレクトリの中にあるディレクトリを取得する
     117    @author OverTaker
     118    @date   2007/11/11
     119    @return ディレクトリの配列
     120    */
    75121    Function GetDirectories() As List<DirectoryInfo>
    76122        Return GetDirectories("?*")
    77123    End Function
    78124
     125    /*!
     126    @brief  ディレクトリの中にあるディレクトリを取得する
     127    @author OverTaker
     128    @date   2007/11/11
     129    @param  サーチするディレクトリ名のパターン
     130    @return パターンに適合したディレクトリの配列
     131    */
    79132    Function GetDirectories(searchPattern As String) As List<DirectoryInfo>
    80133        Dim infos As List<FileSystemInfo>
     
    91144    End Function
    92145
     146    /*!
     147    @brief  ディレクトリの中にあるディレクトリを取得する
     148    @author OverTaker
     149    @date   2007/11/11
     150    @param  サーチするディレクトリ名のパターン
     151    @param  サーチする範囲
     152    @return サーチした範囲にあるパターンに適合したディレクトリの配列
     153    */
    93154    Function GetDirectories(searchPattern As String, searchOption As SearchOption) As List<DirectoryInfo>
    94155        Select Case searchOption
     
    111172    End Function
    112173
     174    /*!
     175    @brief  ディレクトリの中にあるファイルを取得する
     176    @author OverTaker
     177    @date   2007/11/11
     178    @return ファイルの配列
     179    */
    113180    Function GetFiles() As List<FileInfo>
    114181        Return GetFiles("?*")
    115182    End Function
    116183
     184    /*!
     185    @brief  ディレクトリの中にあるファイルを取得する
     186    @author OverTaker
     187    @date   2007/11/11
     188    @param  サーチするファイル名のパターン
     189    @return パターンに適合したファイルの配列
     190    */
    117191    Function GetFiles(searchPattern As String) As List<FileInfo>
    118192        Dim infos As List<FileSystemInfo>
     
    129203    End Function
    130204
     205    /*!
     206    @brief  ディレクトリの中にあるファイルを取得する
     207    @author OverTaker
     208    @date   2007/11/11
     209    @param  サーチするファイル名のパターン
     210    @param  サーチする範囲
     211    @return サーチした範囲にあるパターンに適合したディレクトリの配列
     212    */
    131213    Function GetFiles(searchPattern As String, searchOption As SearchOption) As List<FileInfo>
    132214        Select Case searchOption
     
    150232    End Function
    151233
     234    /*!
     235    @brief  ディレクトリの中にあるディレクトリやファイルを取得する
     236    @author OverTaker
     237    @date   2007/11/11
     238    @return ディレクトリやファイルの配列
     239    */
    152240    Function GetFileSystemInfos() As List<FileSystemInfo>
    153241        Return GetFileSystemInfos("?*")
    154242    End Function
    155243
     244    /*!
     245    @brief  ディレクトリの中にあるディレクトリやファイルを取得する
     246    @author OverTaker
     247    @date   2007/11/11
     248    @param  サーチする名前のパターン
     249    @return パターンに適合したディレクトリやファイルの配列
     250    */
    156251    Function GetFileSystemInfos(searchPattern As String) As List<FileSystemInfo>
    157252        Dim find As HANDLE
     
    184279    End Function
    185280
     281    /*!
     282    @brief  ディレクトリを移動する
     283    @author OverTaker
     284    @date   2007/11/11
     285    @param  移動先
     286    */
    186287    Sub MoveTo(destDirName As String)
    187288        If MoveFile(ToTCStr(FullPath), ToTCStr(destDirName)) = FALSE Then
  • trunk/Include/Classes/System/IO/Path.ab

    r388 r404  
    1 ' System/IO/Path.ab
     1/*!
     2@file   Classes/System/IO/Path.ab
     3@brief  ファイルパス文字列を操作する
     4@author OverTaker
     5*/
    26
    37#require <Classes/System/Environment.ab>
    4 
    58
    69Namespace System
    710Namespace IO
    8 
    911
    1012Class Path
    1113Public
    1214    Static AltDirectorySeparatorChar = &H2F As StrChar '/
    13     Static DirectorySeparatorChar = &H5C As StrChar    '\
    14     Static PathSeparator = &H3B As StrChar             ';
    15     Static VolumeSeparatorChar = &H3A As StrChar       ':
    16 
     15    Static DirectorySeparatorChar    = &H5C As StrChar '\
     16    Static PathSeparator             = &H3B As StrChar ';
     17    Static VolumeSeparatorChar       = &H3A As StrChar ':
     18
     19    /*!
     20    @brief  ファイル名を取得する
     21    @author OverTaker
     22    @date   
     23    @param  ファイルパス
     24    @return ファイル名
     25    */
    1726    Static Function GetFileName(path As String) As String
    18         Return path.Remove(0, getLastSeparatorPosision(path) + 1)
    19     End Function
    20 
     27        CheckPath(path)
     28        Return path.Remove(0, GetLastSeparatorIndex(path) + 1)
     29    End Function
     30
     31    /*!
     32    @brief  拡張子を除いたファイル名を取得する
     33    @author OverTaker
     34    @date   
     35    @param  ファイルパス
     36    @return ファイル名
     37    */
    2138    Static Function GetFileNameWithoutExtension(path As String) As String
     39        CheckPath(path)
    2240        Dim fileName = GetFileName(path) As String
    23         Dim extPos = getExtensionPosition(fileName) As Long
     41        Dim extPos = GetExtensionIndex(fileName) As Long
    2442        If extPos = -1 Then Return ""
    2543
     
    2745    End Function
    2846
    29     '手抜き
     47    /*!
     48    @brief  ランダムなファイル名を取得する
     49    @author OverTaker
     50    @date   
     51    @param  ファイルパス
     52    @return ファイル名
     53    */
    3054    Static Function GetRandomFileName() As String
    3155        Randomize
     
    3559    End Function
    3660
     61    /*!
     62    @brief  ファイルの拡張子を取得する
     63    @author OverTaker
     64    @date   
     65    @param  ファイルパス
     66    @return 拡張子(.を含む)
     67    */
    3768    Static Function GetExtension(path As String) As String
    38         Dim extPos = getExtensionPosition(path) As Long
     69        CheckPath(path)
     70        Dim extPos = GetExtensionIndex(path) As Long
    3971        If extPos = -1 Then Return ""
    4072
     
    4274    End Function
    4375
     76    /*!
     77    @brief  ファイル拡張子を変更する
     78    @author OverTaker
     79    @date   
     80    @param  拡張子(.を含む)
     81    @return 拡張子を変更したファイルパス
     82    */
    4483    Static Function ChangeExtension(path As String, extension As String) As String
    45         Dim extPos = getExtensionPosition(path) As Long
     84        Dim extPos = GetExtensionIndex(path) As Long
    4685        If extPos => 0 Then
    4786            path = path.Remove(extPos)
    4887        End If
    4988
     89        CheckPath(path)
    5090        Return path + extension
    5191    End Function
    5292
    53     Static Function HasExtension(ByRef path As String) As Boolean
     93    /*!
     94    @brief  ファイルパスの拡張子が含まれるかどうか
     95    @author OverTaker
     96    @date   
     97    @param  ファイルパス
     98    @return 拡張子があればTure,なければFalse
     99    */
     100    Static Function HasExtension(path As String) As Boolean
     101        CheckPath(path)
    54102        If GetExtension(path) <> "" Then
    55103            Return True
     
    59107    End Function
    60108
     109    /*!
     110    @brief  一時ファイルを作成し、ファイルパスを取得する
     111    @author OverTaker
     112    @date   
     113    @return 一時ファイルを示すファイルパス
     114    */
    61115    Static Function GetTempFileName() As String
    62116        Dim tempPathSize = __GetTempPath(0, 0)
     
    76130        Return New String(tempFileName, len As Long)
    77131    End Function
    78 
     132   
     133    /*!
     134    @brief  システムの一時フォルダを取得する
     135    @author OverTaker
     136    @date   
     137    @return ファイルパス
     138    */
    79139    Static Function GetTempPath() As String
    80140        Dim size = __GetTempPath(0, 0)
     
    85145    End Function
    86146
     147    /*!
     148    @brief  フルパスを取得する
     149    @author OverTaker
     150    @date   
     151    @param  ファイルパス
     152    @return ファイルパス
     153    */
    87154    Static Function GetFullPath(path As String) As String
     155        CheckPath(path)
    88156        If IsPathRooted(path) Then
    89157            Return path
     
    93161    End Function
    94162
     163    /*!
     164    @brief  ひとつ上のディレクトリを取得する
     165    @author OverTaker
     166    @date   
     167    @param  ファイルパス
     168    @return ひとつ上のディレクトリを示すファイルパス
     169    */
    95170    Static Function GetDirectoryName(path As String) As String
    96         Dim lastSepPos = getLastSeparatorPosision(path) As Long
     171        CheckPath(path)
     172        Dim lastSepPos = GetLastSeparatorIndex(path) As Long
    97173        If lastSepPos = -1 Then Return ""
    98174
     
    104180    End Function
    105181
     182    /*!
     183    @brief  ルートディレクトリを取得する
     184    @author OverTaker
     185    @date   
     186    @param  ファイルパス
     187    @return ルートディレクトリを示すパス
     188    */
    106189    Static Function GetPathRoot(path As String) As String
     190        CheckPath(path)
    107191        If IsPathRooted(path) Then
    108192            Return path.Remove(3)
     
    112196    End Function
    113197
     198    /*!
     199    @brief  パスにルートディレクトリが含まれるかどうか
     200    @author OverTaker
     201    @date   
     202    @param  ファイルパス
     203    @return 含まれる場合True,そうでない場合False
     204    */
    114205    Static Function IsPathRooted(path As String) As Boolean
     206        CheckPath(path)
    115207        If path.IndexOf(Chr$(VolumeSeparatorChar), 1, 1) = 1 Then
    116208            Return True
     
    120212    End Function
    121213
     214    /*!
     215    @brief  二つのパスを結合します
     216    @author OverTaker
     217    @date   
     218    @param  結合されるファイルパス
     219    @param  結合するファイルパス
     220    @return 結合されたファイルパス
     221    */
    122222    Static Function Combine(path1 As String, path2 As String) As String
     223        CheckPath(path1)
     224        CheckPath(path2)
    123225        If path1.LastIndexOf(VolumeSeparatorChar) And path1.Length = 2 Then
    124226            Return path1 + path2
     
    133235
    134236Private
    135     Static Function getExtensionPosition(path As String) As Long
    136         Dim lastSepPos = getLastSeparatorPosision(path) As Long
    137         If lastSepPos = -1 Then
    138             lastSepPos = 0
    139         End If
    140         getExtensionPosition = path.LastIndexOf(Asc("."), ELM(path.Length), path.Length - lastSepPos)
    141     End Function
    142 
    143     Static Function getLastSeparatorPosision(path As String) As Long
    144         Dim lastSepPos = path.LastIndexOf(DirectorySeparatorChar) As Long
    145         If lastSepPos <> -1 Then Return lastSepPos
    146 
    147         lastSepPos = path.LastIndexOf(VolumeSeparatorChar)
    148         Return lastSepPos
     237    Static Const InvalidPathChars = Ex"\q<>|\0\t" As String
     238
     239    /*!
     240    @brief  無効なパス文字列がないか調べる
     241    @author OverTaker
     242    @date   
     243    @param  ファイルパス
     244    */
     245    Static Sub CheckPath(path As String)
     246        Dim i As Long
     247        For i = 0 To ELM(InvalidPathChars.Length)
     248            If path.Contains(InvalidPathChars.Substring(i, 1)) Then
     249                Throw
     250            End If
     251        Next
     252    End Sub
     253
     254    /*!
     255    @brief  ファイルの拡張子の位置を取得する
     256    @author OverTaker
     257    @date   
     258    @param  ファイルパス
     259    @return 0から始まるインデックス値。みつからない場合-1
     260    */
     261    Static Function GetExtensionIndex(path As String) As Long
     262        Dim lastSepIndex = GetLastSeparatorIndex(path) As Long
     263        If lastSepIndex = -1 Then lastSepIndex = 0
     264        Return path.LastIndexOf(Asc("."), ELM(path.Length), path.Length - lastSepIndex)
     265    End Function
     266
     267    /*!
     268    @brief  最も後ろにあるディレクトリ区切り文字の位置を取得する
     269    @author OverTaker
     270    @date   
     271    @param  ファイルパス
     272    @return 0から始まるインデックス値。みつからない場合-1
     273    */
     274    Static Function GetLastSeparatorIndex(path As String) As Long
     275        Return System.Math.Max( path.LastIndexOf(DirectorySeparatorChar),
     276                                path.LastIndexOf(VolumeSeparatorChar) )
    149277    End Function
    150278End Class
Note: See TracChangeset for help on using the changeset viewer.