none
FileSystemObject in C#?? RRS feed

  • Question

  •  

    Hi,

     

    I have some VBA that uses the FileSystemObject to go through the files in a directory and put the properties of each file into a spreadsheet. It works as follows:

     

    --------------------------------------------------------------------------------------------------

    Dim FSO As Scripting.FileSystemObject
    Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
    Dim FileItem As Scripting.File
    Dim r As Long
        Set FSO = New Scripting.FileSystemObject
        Set SourceFolder = FSO.GetFolder("C:\Folder")
           
        r = Range("A65536").End(xlUp).Row + 1
        For Each FileItem In SourceFolder.Files
            ' display file properties
            Cells(r, 1).Formula = FileItem.Path
            Cells(r, 2).Formula = FileItem.Name
            Cells(r, 4).Formula = FileItem.DateCreated
            Cells(r, 5).Formula = FileItem.DateLastAccessed
            Cells(r, 6).Formula = FileItem.DateLastModified
     

            r = r + 1 ' next row number
        Next FileItem
      

       Columns("A:H").AutoFit
        Set FileItem = Nothing
        Set SourceFolder = Nothing
        Set FSO = Nothing
    End Sub

     

    I would like to do something similar except that I want the data to be stored into a SQL Server 2000 table. Creating the table, connection and using the ADO.NET objects is straightforward. My problem is that I cannot seem to get the properties of each file.

    I have tried using the System.IO namespace but cannot seem to find a way to find to get the properties of each file.

     

    e.g. I try doing:

     

    foreach (string s in Directory.GetFiles(FilePath))

    {

        // ??? How do I get the properties?

    }

     

    Any help would be appreciated.

    Kabir

    Monday, July 16, 2007 1:45 PM

All replies