Ignore:
Timestamp:
Feb 17, 2008, 12:51:20 PM (16 years ago)
Author:
OverTaker
Message:

System/IO/Directory.ab実装。例外処理を徐々に実装。

File:
1 edited

Legend:

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

    r337 r407  
    44Namespace IO
    55
     6/*!
     7@brief  ディレクトリの情報を取得したり操作するクラス
     8*/
     9
    610Class Directory
     11Public
     12
     13    '----------------------------------------------------------------
     14    ' パブリック メソッド
     15    '----------------------------------------------------------------
     16
     17    /*!
     18    @brief  ディレクトリを作成する
     19    @param  作成するディレクトリのファイルパス
     20    @return 作成されたディレクトリのDirctoryInfo
     21    */
    722    Static Function CreateDirectory(path As String) As DirectoryInfo
    8     End Function
    9 
     23        Dim info = New DirectoryInfo(path)
     24        info.Create()
     25        Return info
     26    End Function
     27
     28    /*
    1029    Static Function CreateDirectory(path As String, directorySecurity As DirectorySecurity) As DirectoryInfo
    11     End Function
    12 
     30    End Function */
     31
     32    /*!
     33    @brief  ディレクトリを削除する
     34    ディレクトリが開き出ない場合は削除されない
     35    @param  消去するディレクトリのファイルパス
     36    */
    1337    Static Sub Delete(path As String)
    14     End Sub
    15 
     38        Dim info = New DirectoryInfo(path)
     39        info.Delete()
     40    End Sub
     41
     42    /*!
     43    @brief  ディレクトリを削除する
     44    @param  削除するディレクトリのファイルパス
     45    @param  ディレクトリの中身も消去する場合True
     46    */
    1647    Static Sub Delete(path As String, recursive As Boolean)
    17     End Sub
    18 
     48        Dim info = New DirectoryInfo(path)
     49        info.Delete(recursive)
     50    End Sub
     51
     52    /*!
     53    @brief  ディレクトリが存在するかどうか
     54    @param  調べるディレクトリのファイルパス
     55    @retval True  存在する
     56    @retval False 存在しない
     57    */
    1958    Static Function Exist(path As String) As Boolean
    20     End Function
    21 
     59        Dim info = New DirectoryInfo(path)
     60        Return info.Exists
     61    End Function
     62
     63    /*!
     64    @brief  カレントディレクトリを取得する
     65    @return カレントディレクトリを示すパス
     66    */
    2267    Static Function GetCurrentDirectory() As String
    23     End Function
    24 
     68        Return System.Environment.CurrentDirectory
     69    End Function
     70
     71    /*
    2572    Static Function GetAccessControl(path As String) As DirectorySecurity
    26     End Function 
     73    End Function
    2774
    2875    Static Function GetAccessControl(path As String, includeSections As System.Security.AccessControl.AccessControlSections) As DirectorySecurity
    2976    End Function
    30 
    31     Static Function GetCreationTime(oath As String) As DateTime
    32     End Function
    33 
     77    */
     78
     79    /*!
     80    @brief  ディレクトリの作成日を取得する
     81    @param  ディレクトリを示すパス
     82    @return 作成日
     83    */
     84    Static Function GetCreationTime(path As String) As DateTime
     85        Dim info = New DirectoryInfo(path)
     86        Return info.CreationTime
     87    End Function
     88
     89    /*!
     90    @brief  ディレクトリの作成日をUTC時刻で取得する
     91    @param  ディレクトリを示すパス
     92    @return 作成日(UTC)
     93    */
    3494    Static Function GetCreationTimeUtc(path As String) As DateTime
    35     End Function
    36 
     95        Dim info = New DirectoryInfo(path)
     96        Return info.CreationTimeUtc
     97    End Function
     98
     99    /*!
     100    @brief  ディレクトリ内のディレクトリを列挙する
     101    @param  中身を調べるディレクトリのパス
     102    @return ディレクトリのパス文字列が列挙された配列
     103    */
    37104    Static Function GetDirectories(path As String) As List<String>
    38     End Function
    39 
     105        Return GetDirectories(path, "?*", SearchOption.TopDirectoryOnly)
     106    End Function
     107
     108    /*!
     109    @brief  ディレクトリ内のディレクトリを列挙する
     110    @param  中身を調べるディレクトリのパス
     111    @param  サーチするディレクトリ名のパターン
     112    @return ディレクトリのパス文字列が列挙された配列
     113    */
    40114    Static Function GetDirectories(path As String, searchPattern As String) As List<String>
    41     End Function
    42 
     115        Return GetDirectories(path, searchPattern, SearchOption.TopDirectoryOnly)
     116    End Function
     117
     118    /*!
     119    @brief  ディレクトリ内のディレクトリを列挙する
     120    @param  中身を調べるディレクトリのパス
     121    @param  サーチするディレクトリ名のパターン
     122    @param  サーチする範囲
     123    @return ディレクトリのパス文字列が列挙された配列
     124    */
    43125    Static Function GetDirectories(path As String, searchPattern As String, searchOption As SearchOption) As List<String>
    44     End Function
    45 
     126        Dim info = New DirectoryInfo(path)
     127        Dim infos = info.GetDirectories(searchPattern, searchOption) As List<DirectoryInfo>
     128        Dim enumerator = infos.GetEnumerator()
     129        Dim list As List<String>
     130        While enumerator.MoveNext()
     131            list.Add(enumerator.Current.ToString)
     132        Wend
     133        Return list
     134    End Function
     135
     136    /*!
     137    @brief  ディレクトリのルートディレクトリを取得する
     138    @param  ディレクトリのパス
     139    @return ルートディレクトリ
     140    */
    46141    Static Function GetDirectoryRoot(path As String) As String
    47     End Function
    48 
     142        Return Path.GetPathRoot(path)
     143    End Function
     144
     145    /*!
     146    @brief  ディレクトリ内のファイルを列挙する
     147    @param  中身を調べるディレクトリのパス
     148    @return ファイルのパス文字列が列挙された配列
     149    */
    49150    Static Function GetFiles(path As String) As List<String>
    50     End Function
    51 
     151        Return GetFiles(path, "?*", SearchOption.TopDirectoryOnly)
     152    End Function
     153
     154    /*!
     155    @brief  ディレクトリ内のファイルを列挙する
     156    @param  中身を調べるディレクトリのパス
     157    @param  サーチするファイル名のパターン
     158    @return ファイルのパス文字列が列挙された配列
     159    */
    52160    Static Function GetFiles(path As String, searchPattern As String) As List<String>
    53     End Function
    54 
     161        Return GetFiles(path, searchPattern, SearchOption.TopDirectoryOnly)
     162    End Function
     163
     164    /*!
     165    @brief  ディレクトリ内のファイルを列挙する
     166    @param  中身を調べるディレクトリのパス
     167    @param  サーチするファイル名のパターン
     168    @param  サーチする範囲
     169    @return ファイルのパス文字列が列挙された配列
     170    */
    55171    Static Function GetFiles(path As String, searchPattern As String, searchOption As SearchOption) As List<String>
    56     End Function
    57 
     172        Dim info = New DirectoryInfo(path)
     173        Dim infos = info.GetFiles(searchPattern, searchOption) As List<FileInfo>
     174        Dim enumerator = infos.GetEnumerator()
     175        Dim list As List<String>
     176        While enumerator.MoveNext()
     177            list.Add(enumerator.Current.ToString)
     178        Wend
     179        Return list
     180    End Function
     181
     182    /*!
     183    @brief  ディレクトリ内を列挙する
     184    @param  中身を調べるディレクトリのパス
     185    @return ファイルやディレクトリのパス文字列が列挙された配列
     186    */
    58187    Static Function GetFileSystemEnties(path As String) As List<String>
    59     End Function
    60 
     188        Return GetFileSystemEnties(path, "?*")
     189    End Function
     190
     191    /*!
     192    @brief  ディレクトリ内を列挙する
     193    @param  中身を調べるディレクトリのパス
     194    @param  サーチするファイル名のパターン
     195    @return ファイルやディレクトリのパス文字列が列挙された配列
     196    */
    61197    Static Function GetFileSystemEnties(path As String, searchPattern As String) As List<String>
    62     End Function
    63 
     198        Dim info = New DirectoryInfo(path)
     199        Dim infos = info.GetFileSystemInfos(searchPattern) As List<FileSystemInfo>
     200        Dim enumerator = infos.GetEnumerator()
     201        Dim list As List<String>
     202        While enumerator.MoveNext()
     203            list.Add(enumerator.Current.ToString)
     204        Wend
     205        Return list
     206    End Function
     207
     208    /*!
     209    @brief  ディレクトリの最終アクセス日を取得する
     210    @param  ディレクトリのパス
     211    @return 最終アクセス日
     212    */
    64213    Static Function GetLastAccessTime(path As String) As DateTime
    65     End Function
    66 
     214        Dim info = New DirectoryInfo(path)
     215        Return info.LastAccessTime
     216    End Function
     217
     218    /*!
     219    @brief  ディレクトリの最終アクセス日をUTC時刻で取得する
     220    @param  ディレクトリのパス
     221    @return 最終アクセス日(UTC)
     222    */
    67223    Static Function GetLastAccessTimeUtc(path As String) As DateTime
    68     End Function
    69 
     224        Dim info = New DirectoryInfo(path)
     225        Return info.LastAccessTimeUtc
     226    End Function
     227
     228    /*!
     229    @brief  ディレクトリの最終書き込み日を取得する
     230    @param  ディレクトリのパス
     231    @return 最終書き込み日
     232    */
    70233    Static Function GetLastWriteTime(path As String) As DateTime
    71     End Function
    72 
     234        Dim info = New DirectoryInfo(path)
     235        Return info.LastWriteTime
     236    End Function
     237
     238    /*!
     239    @brief  ディレクトリの最終書き込み日をUTC時刻で取得する
     240    @param  ディレクトリのパス
     241    @return 最終書き込み日(UTC)
     242    */
    73243    Static Function GetLastWriteTimeUtc(path As String) As DateTime
    74     End Function
    75 
     244        Dim info = New DirectoryInfo(path)
     245        Return info.LastWriteTimeUtc
     246    End Function
     247
     248    /*!
     249    @brief  使用可能な論理ドライブを列挙する
     250    @return 論理ドライブを列挙したパス文字列
     251    */
    76252    Static Function GetLogicalDrives() As List<String>
    77     End Function
    78 
     253        Dim drives = WIN32API_GetLogicalDrives() As DWord
     254        If drives <> 0 Then
     255            Dim list As List<String>
     256            Dim i As SByte
     257            For i = 0 To 25
     258                If (drives and (1 << i)) <> 0 Then
     259                    list.Add(Chr$(Asc("A") + i) + ":\")
     260                End If
     261            Next
     262            Return list
     263        Else
     264            Throw New IOException("Directory.GetLogicalDrives: Failed to GetLogicalDirives.")
     265        End If
     266    End Function
     267
     268    /*!
     269    @brief  ディレクトリのひとつ上のディレクトリを取得する
     270    @param  ディレクトリのパス
     271    @return ひとつ上のディレクトリ
     272    */
    79273    Static Function GetParent(path As String) As DirectoryInfo
    80     End Function
    81 
     274        Return New DirectoryInfo(Path.GetDirectoryName(path))
     275    End Function
     276
     277    /*!
     278    @brief  ディレクトリを移動する
     279    @param  移動元のディレクトリのパス
     280    @param  移動後のディレクトリのパス
     281    */
    82282    Static Sub Move(sourceDirName As String, destDirName As String)
    83     End Sub
    84 
     283        Dim info = New DirectoryInfo(sourceDirName)
     284        info.MoveTo(destDirName)
     285    End Sub
     286
     287    /*
    85288    Static Sub SetAccessControl(path As String, directorySecurity As DirectorySecurity)
    86289    End Sub
    87 
     290    */
     291
     292    /*!
     293    @brief  ディレクトリの作成日を設定する
     294    @param  ディレクトリのパス
     295    @param  作成日
     296    */
    88297    Static Sub SetCreationTime(path As String, creationTime As DateTime)
    89     End Sub
    90 
     298        Dim info = New DirectoryInfo(path)
     299        info.CreationTime = creationTime
     300    End Sub
     301
     302    /*!
     303    @brief  ディレクトリの作成日をUTC時刻で設定する
     304    @param  ディレクトリのパス
     305    @param  作成日(UTC)
     306    */
    91307    Static Sub SetCreationTimeUtc(path As String, creationTime As DateTime)
    92     End Sub
    93 
     308        Dim info = New DirectoryInfo(path)
     309        info.CreationTimeUtc = creationTime
     310    End Sub
     311
     312    /*!
     313    @brief  カレントディレクトリを設定する
     314    @param  ディレクトリのパス
     315    */
    94316    Static Sub SetCurrentDirectory(path As String)
    95     End Sub
    96 
     317        System.Environment.CurrentDirectory = path
     318    End Sub
     319
     320    /*!
     321    @brief  ディレクトリの最終アクセス日を設定する
     322    @param  ディレクトリのパス
     323    @param  最終アクセス日
     324    */
    97325    Static Sub SetLastAccessTime(path As String, lastAccessTime As DateTime)
    98     End Sub
    99 
     326        Dim info = New DirectoryInfo(path)
     327        info.LastAccessTime = lastAccessTime
     328    End Sub
     329
     330    /*!
     331    @brief  ディレクトリの最終アクセス日をUTC時刻で設定する
     332    @param  ディレクトリのパス
     333    @param  最終アクセス日(UTC)
     334    */
    100335    Static Sub SetLastAccessTimeUtc(path As String, lastAccessTime As DateTime)
    101     End Sub
    102 
     336        Dim info = New DirectoryInfo(path)
     337        info.LastAccessTimeUtc = lastAccessTime
     338    End Sub
     339
     340    /*!
     341    @brief  ディレクトリの最終書き込み日を設定する
     342    @param  ディレクトリのパス
     343    @param  最終書き込み日
     344    */
    103345    Static Sub SetLastWriteTime(path As String, lastWriteTime As DateTime)
    104     End Sub
    105 
     346        Dim info = New DirectoryInfo(path)
     347        info.LastWriteTime = lastWriteTime
     348    End Sub
     349
     350    /*!
     351    @brief  ディレクトリの最終書き込み日をUTC時刻で設定する
     352    @param  ディレクトリのパス
     353    @param  最終書き込み日(UTC)
     354    */
    106355    Static Sub SetLastWriteTimeUtc(path As String, lastWriteTime As DateTime)
     356        Dim info = New DirectoryInfo(path)
     357        info.LastWriteTimeUtc = lastWriteTime
    107358    End Sub
    108359End Class
     360
     361/* 名前が被ってメソッドから呼び出せない */
     362Function WIN32API_GetLogicalDrives() As DWord
     363    Return GetLogicalDrives()
     364End Function
    109365
    110366End Namespace
Note: See TracChangeset for help on using the changeset viewer.