Changeset 318


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

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

Location:
trunk/Include/Classes/System/IO
Files:
5 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
  • trunk/Include/Classes/System/IO/FileInfo.ab

    r271 r318  
    44
    55Class FileInfo
     6    Inherits FileSystemInfo
     7Public
     8    Sub FileInfo(path As String)
     9        OriginalPath = path
     10        FullPath = Path.GetFullPath(path)
     11        Refresh()
     12    End Sub
     13
     14    Sub ~FileInfo()
     15    End Sub
     16
     17    '----------------------------------------------------------------
     18    ' Public properties
     19    '----------------------------------------------------------------
     20
     21    Function Directory() As DirectoryInfo
     22        Return New DirectoryInfo(Path.GetDirectoryName(FullPath))
     23    End Function
     24
     25    Function DirectoryName() As String
     26        Return Path.GetDirectoryName(FullPath)
     27    End Function
     28
     29    Function IsReadOnly() As Boolean
     30        If (Attributes And FILE_ATTRIBUTE_READONLY) = FILE_ATTRIBUTE_READONLY Then
     31            Return True
     32        Else
     33            Return False
     34        End If
     35    End Function
    636End Class
     37
    738
    839
  • trunk/Include/Classes/System/IO/FileSystemInfo.ab

    r292 r318  
    1212    OriginalPath As String
    1313Public
    14     'Public Properties
    15     Function Attributes() As FileAttributes
    16         Select Case m_FileAttributes
    17             Case FILE_ATTRIBUTE_ARCHIVE
    18                 Return FileAttributes.Archive
    19             Case FILE_ATTRIBUTE_COMPRESSED
    20                 Return FileAttributes.Compressed
    21             Case FILE_ATTRIBUTE_DIRECTORY
    22                 Return FileAttributes.Directory
    23             Case FILE_ATTRIBUTE_ENCRYPTED
    24                 Return FileAttributes.Encrypted
    25             Case FILE_ATTRIBUTE_HIDDEN
    26                 Return FileAttributes.Hidden
    27             Case FILE_ATTRIBUTE_NORMAL
    28                 Return FileAttributes.Normal
    29             Case FILE_ATTRIBUTE_OFFLINE
    30                 Return FileAttributes.Offline
    31             Case FILE_ATTRIBUTE_READONLY
    32                 Return FileAttributes.ReadOnly
    33             Case FILE_ATTRIBUTE_REPARSE_POINT
    34                 Return FileAttributes.ReparsePoint
    35             Case FILE_ATTRIBUTE_SPARSE_FILE
    36                 Return FileAttributes.SparseFile
    37             Case FILE_ATTRIBUTE_SYSTEM
    38                 Return FileAttributes.System
    39             Case FILE_ATTRIBUTE_TEMPORARY
    40                 Return FileAttributes.Temporary
    41             Case Else
    42                 'Exception
    43                 Debug
    44         End Select
     14
     15    Override Function Equals( object As Object ) As Boolean
     16        If This.ToString = object.ToString Then
     17            Return True
     18        Else
     19            Return False
     20        End If
    4521    End Function
    4622
    47     Sub Attributes(ByRef value As FileAttributes)
    48         Dim attributes As DWord
    49         Select Case value
    50             Case FileAttributes.Archive
    51                 attributes = FILE_ATTRIBUTE_ARCHIVE
    52             Case FileAttributes.Compressed
    53                 attributes = FILE_ATTRIBUTE_COMPRESSED
    54             Case FileAttributes.Directory
    55                 attributes = FILE_ATTRIBUTE_DIRECTORY
    56             Case FileAttributes.Hidden
    57                 attributes = FILE_ATTRIBUTE_HIDDEN
    58             Case FileAttributes.Normal
    59                 attributes = FILE_ATTRIBUTE_NORMAL
    60             Case FileAttributes.Offline
    61                 attributes = FILE_ATTRIBUTE_OFFLINE
    62             Case FileAttributes.ReadOnly
    63                 attributes = FILE_ATTRIBUTE_READONLY
    64             Case FileAttributes.System
    65                 attributes = FILE_ATTRIBUTE_SYSTEM
    66             Case FileAttributes.Temporary
    67                 attributes = FILE_ATTRIBUTE_TEMPORARY
    68             Case Else
    69                 'Exception
    70                 Exit Sub
    71         End Select
     23    Override Function ToString() As String
     24        Return FullPath
     25    End Function
    7226
    73         If SetFileAttributes(FullPath, attributes) = FALSE Then
     27    'Public Properties
     28    Function Attributes() As DWord'FileAttributes
     29        Return m_FileAttributes
     30    End Function
     31
     32    Sub Attributes(value As DWord)
     33        If SetFileAttributes(FullPath, value) = FALSE Then
    7434            'Exception
    7535            Debug
  • trunk/Include/Classes/System/IO/index.ab

    r271 r318  
    33#require "DriveInfo.ab"
    44#require "File.ab"
     5#require "FileInfo.ab"
    56#require "FileStream.ab"
    67#require "FileSystemInfo.ab"
  • trunk/Include/Classes/System/IO/misc.ab

    r262 r318  
    77    End
    88End Enum
     9
     10Enum SearchOption
     11    AllDirectories
     12    TopDirectoryOnly
     13End Enum
Note: See TracChangeset for help on using the changeset viewer.