Ignore:
Timestamp:
Aug 28, 2007, 9:16:10 PM (17 years ago)
Author:
OverTaker
Message:

DirectoryInfo.GetFileSystemInfos()中心に色々と...

File:
1 edited

Legend:

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

    r285 r318  
     1Imports System.Collections.Generic
    12
    23Namespace System
     
    1718    'Public Property
    1819    Function Parent() As DirectoryInfo
    19         Dim dirInfo As DirectoryInfo(Path.GetDirectoryName(FullPath))
    20         Return dirInfo
     20        Return New DirectoryInfo(Path.GetDirectoryName(FullPath))
    2121    End Function
    2222
    2323    Function Root() As DirectoryInfo
    24         Dim dirInfo As DirectoryInfo(Path.GetPathRoot(FullPath))
    25         Return dirInfo
     24        Return New DirectoryInfo(Path.GetPathRoot(FullPath))
    2625    End Function
    2726
     
    7574    End Function*/
    7675
    77 /*  Function GetDirectories() As Array
     76    Function GetDirectories() As List<DirectoryInfo>
     77        Return GetDirectories("?*")
     78    End Function
     79
     80    Function GetDirectories(searchPattern As String) As List<DirectoryInfo>
     81        Dim infos As List<FileSystemInfo>
     82        infos = GetFileSystemInfos(searchPattern)
     83
     84        Dim dirs As List<DirectoryInfo>
     85        Dim i As Long
     86        For i = 0 To ELM(infos.Count)
     87            If infos[i].GetType.ToString() = "DirectoryInfo" Then
     88                dirs.Add(infos[i] As DirectoryInfo)
     89            End If
     90        Next
     91        Return dirs
     92    End Function
     93
     94/*  Function GetDirectories(searchPattern As String, searchOption As SearchOption) As List<DirectoryInfo>
     95        If searchOption = SearchOption.TopDirectoryOnly Then
     96            Return GetDirectories(searchPattern)
     97        Else
     98            Dim dirs As List<DirectoryInfo>
     99            dirs = GetDirectories(searchPattern)
     100            Dim i As Long
     101
     102        End If
    78103    End Function*/
    79104
    80 /*  Function GetDirectories(searchPattern As String) As Array
     105    Function GetFiles() As List<FileInfo>
     106        Return GetFiles("?*")
     107    End Function
     108
     109    Function GetFiles(searchPattern As String) As List<FileInfo>
     110        Dim infos As List<FileSystemInfo>
     111        infos = GetFileSystemInfos(searchPattern)
     112
     113        Dim files As List<FileInfo>
     114        Dim i As Long
     115        For i = 0 To ELM(infos.Count)
     116            If infos[i].GetType.ToString() = "FileInfo" Then
     117                files.Add(infos[i] As FileInfo)
     118            End If
     119        Next
     120        Return files
     121    End Function
     122
     123/*  Function GetFiles(searchPattern As String, searchOption As SearchOption) As List<FileInfo>
    81124    End Function*/
    82125
    83 /*  Function GetDirectories(searchPattern As String, searchOption As SearchOption) As Array
    84     End Function*/
     126    Function GetFileSystemInfos() As List<FileSystemInfo>
     127        Return GetFileSystemInfos("?*")
     128    End Function
    85129
    86 /*  Function GetFiles() As Array
    87     End Function*/
     130    Function GetFileSystemInfos(searchPattern As String) As List<FileSystemInfo>
     131        Dim find As HANDLE
     132        Dim findData As WIN32_FIND_DATA
     133        find = FindFirstFile(ToTCStr(Path.Combine(FullPath, searchPattern)), findData)
     134        If find = INVALID_HANDLE_VALUE Then
     135            debug 'Exception
     136            Return Nothing
     137        End If
    88138
    89 /*  Function GetFiles(searchPattern As String) As Array
    90     End Function*/
     139        Dim files As List<FileSystemInfo>
     140        Dim lastError = GetLastError() As DWord
     141        Dim i As Long
     142        While lastError <> ERROR_NO_MORE_FILES
     143            If i > 1 Then
     144                Dim s = New String(findData.cFileName As PCTSTR)
     145                If (findData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
     146                    files.Add(New DirectoryInfo(Path.Combine(FullPath, s)))
     147                Else
     148                    files.Add(New FileInfo(Path.Combine(FullPath, s)))
     149                End If
     150            End If
    91151
    92 /*  Function GetFiles(searchPattern As String, searchOption As SearchOption) As Array
    93     End Function*/
    94 
    95 /*  Function GetFileSystemInfos() As Array
    96     End Function*/
    97 
    98 /*  Function GetFileSystemInfos(searchPattern As String) As Array
    99     End Function*/
     152            If FindNextFile(find, findData) = False Then
     153                lastError = GetLastError()
     154                If lastError <> ERROR_NO_MORE_FILES Then
     155                    debug 'Exception
     156                    Return Nothing
     157                End If
     158            End If
     159            i++
     160        Wend
     161        Return files
     162    End Function
    100163
    101164    Sub MoveTo(destDirName As String)
     
    110173End Class
    111174
    112 Enum SearchOption
    113     AllDirectories
    114     TopDirectoryOnly
    115 End Enum
    116 
    117175End Namespace
    118176End Namespace
Note: See TracChangeset for help on using the changeset viewer.