Ignore:
Timestamp:
Sep 8, 2007, 10:59:51 AM (17 years ago)
Author:
OverTaker
Message:

Directoryクラス新規作成。DirectoryInfo.FilesのAllDirectories実装。(変なところでエラーになって動かない)

File:
1 edited

Legend:

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

    r326 r327  
    9393
    9494    Function GetDirectories(searchPattern As String, searchOption As SearchOption) As List<DirectoryInfo>
    95         If searchOption = SearchOption.TopDirectoryOnly Then
    96             Return GetDirectories(searchPattern)
    97         ElseIf searchOption = SearchOption.AllDirectories Then
    98             Dim dirs As List<DirectoryInfo>
    99             dirs = GetDirectories(searchPattern)
    100 
    101             Dim subdirs As List<DirectoryInfo>
    102             Dim i As Long, j As Long
    103             For i = 0 To ELM(dirs.Count)
    104                 subdirs = dirs[i].GetDirectories(searchPattern)
    105                 For j = 0 To ELM(subdirs.Count)
    106                     dirs.Add(subdirs[i])
     95        Select Case searchOption
     96            Case SearchOption.TopDirectoryOnly
     97                Return GetDirectories(searchPattern)
     98            Case SearchOption.AllDirectories
     99                Dim dirs As List<DirectoryInfo>
     100                dirs = GetDirectories(searchPattern)
     101
     102                Dim subdirs As List<DirectoryInfo>
     103                Dim i As Long, j As Long
     104                For i = 0 To ELM(dirs.Count)
     105                    subdirs = dirs[i].GetDirectories(searchPattern)
     106                    For j = 0 To ELM(subdirs.Count)
     107                        dirs.Add(subdirs[i])
     108                    Next
    107109                Next
    108             Next
    109             Return dirs
    110         End If
     110                Return dirs
     111        End Select
    111112    End Function
    112113
     
    129130    End Function
    130131
    131 /*  Function GetFiles(searchPattern As String, searchOption As SearchOption) As List<FileInfo>
    132     End Function*/
     132    Function GetFiles(searchPattern As String, searchOption As SearchOption) As List<FileInfo>
     133        Select Case searchOption
     134            Case SearchOption.TopDirectoryOnly
     135                Return GetFiles(searchPattern)
     136            Case SearchOption.AllDirectories
     137                Dim dirs As List<DirectoryInfo>
     138                dirs = GetDirectories(searchPattern, SearchOption.AllDirectories)
     139
     140                Dim files As List<FileInfo>
     141                Dim subfiles As List<FileInfo>
     142                Dim i As Long, j As Long
     143                For i = 0 To ELM(dirs.Count)
     144                    subfiles = dirs[i].GetFiles(searchPattern)
     145                    For j = 0 To ELM(subfiles.Count)
     146                        files.Add(subfiles[j])
     147                    Next
     148                Next
     149                Return files
     150        End Select
     151    End Function
    133152
    134153    Function GetFileSystemInfos() As List<FileSystemInfo>
     
    139158        Dim find As HANDLE
    140159        Dim findData As WIN32_FIND_DATA
    141         find = FindFirstFile(Path.Combine(FullPath, searchPattern), findData)
     160        find = FindFirstFile(ToTCStr(Path.Combine(FullPath, searchPattern)), findData)
    142161        If find = INVALID_HANDLE_VALUE Then
    143162            debug 'Exception
     
    146165
    147166        Dim files As List<FileSystemInfo>
    148         Dim lastError As DWord
    149167        Dim i As Long
    150         While lastError <> ERROR_NO_MORE_FILES
     168        Do
    151169            If i > 1 Then
    152170                Dim s = New String(findData.cFileName As PCTSTR)
     
    157175                End If
    158176            End If
    159 
    160             If FindNextFile(find, findData) = False Then
    161                 lastError = GetLastError()
    162                 If lastError <> ERROR_NO_MORE_FILES Then
    163                     FindClose(find)
    164                     debug 'Exception
    165                     Return Nothing
    166                 End If
    167             End If
    168177            i++
    169         Wend
     178        Loop While FindNextFile(find, findData)
    170179        FindClose(find)
    171         Return files
     180
     181        If GetLastError() = ERROR_NO_MORE_FILES Then
     182            Return files
     183        Else
     184            debug 'Exception
     185            Return Nothing
     186        End If
    172187    End Function
    173188
Note: See TracChangeset for help on using the changeset viewer.