Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

FileSystemObject = User-defined type?

Discussion in 'Information Technology' started by SusanV, Jul 28, 2006.

  1. SusanV

    SusanV
    Expand Collapse
    Guest

    Hi all,

    Access 2000, I'm trying to use a code sample to parse the contents of a
    directory, but am getting a compile error on

    Dim fso As FileSystemObject

    Do I need to set a specific reference to use a FileSystemObject??? I've
    wasted a good hour searching the web and none of the snippets or samples
    mention setting any kind of reference.

    TIA,

    SusanV
     
  2. SusanV

    SusanV
    Expand Collapse
    Guest

    Nevermind, was missing the Scripting runtime reference.

    Doh!

    ;-D

    "SusanV" <svanallen@nospam-mvps.org> wrote in message
    news:%23IFXDffdGHA.3900@TK2MSFTNGP05.phx.gbl...
    > Hi all,
    >
    > Access 2000, I'm trying to use a code sample to parse the contents of a
    > directory, but am getting a compile error on
    >
    > Dim fso As FileSystemObject
    >
    > Do I need to set a specific reference to use a FileSystemObject??? I've
    > wasted a good hour searching the web and none of the snippets or samples
    > mention setting any kind of reference.
    >
    > TIA,
    >
    > SusanV
    >
     
  3. Phillip Windell

    Phillip Windell
    Expand Collapse
    Guest

    Hoowwdy stranger!

    I did these two scripts a couple years ago. They were used in ASP to scan
    through files in a folder on a website then look inside the files for
    specific things ("Include file" references). But the main thing is that
    they do the file/folder recursion and that part of the code should be the
    same.

    http://darkfalz.com/scripts_details.aspx?pstid=1081
    http://darkfalz.com/scripts_details.aspx?pstid=1084


    --
    Phillip Windell [MCP, MVP, CCNA]
    www.wandtv.com



    "SusanV" <svanallen@nospam-mvps.org> wrote in message
    news:eDT%23%23hfdGHA.1260@TK2MSFTNGP05.phx.gbl...
    > Nevermind, was missing the Scripting runtime reference.
    >
    > Doh!
    >
    > ;-D
    >
    > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > news:%23IFXDffdGHA.3900@TK2MSFTNGP05.phx.gbl...
    > > Hi all,
    > >
    > > Access 2000, I'm trying to use a code sample to parse the contents of a
    > > directory, but am getting a compile error on
    > >
    > > Dim fso As FileSystemObject
    > >
    > > Do I need to set a specific reference to use a FileSystemObject??? I've
    > > wasted a good hour searching the web and none of the snippets or samples
    > > mention setting any kind of reference.
    > >
    > > TIA,
    > >
    > > SusanV
    > >

    >
    >
     
  4. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    Are you sure you need to use FSO? I've only ever found one case where FSO
    could do something that I couldn't do using VBA and/or API calls (the
    ability to get the LastUpdated date for a folder)

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no private e-mails, please)


    "SusanV" <svanallen@nospam-mvps.org> wrote in message
    news:eDT%23%23hfdGHA.1260@TK2MSFTNGP05.phx.gbl...
    > Nevermind, was missing the Scripting runtime reference.
    >
    > Doh!
    >
    > ;-D
    >
    > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > news:%23IFXDffdGHA.3900@TK2MSFTNGP05.phx.gbl...
    >> Hi all,
    >>
    >> Access 2000, I'm trying to use a code sample to parse the contents of a
    >> directory, but am getting a compile error on
    >>
    >> Dim fso As FileSystemObject
    >>
    >> Do I need to set a specific reference to use a FileSystemObject??? I've
    >> wasted a good hour searching the web and none of the snippets or samples
    >> mention setting any kind of reference.
    >>
    >> TIA,
    >>
    >> SusanV
    >>

    >
    >
     
  5. SusanV

    SusanV
    Expand Collapse
    Guest

    Good Morning Doug,

    What I'm trying to do is populate a table based on the filenames found in a
    directory tree, then (hopefully) create a search form so users can find
    these files. Files are added (and sometimes moved) by other folks, and we
    don't have control over the directory - and it's driving my guys nuts trying
    to locate stuff.

    Perhaps there is an easier way - but using VBA's Dir function doesn't seem
    to return subfolder contents, as does fso - is there some switch or syntax
    I'm missing?

    TIA,

    Susan

    "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    news:O0uTsBgdGHA.1260@TK2MSFTNGP05.phx.gbl...
    > Are you sure you need to use FSO? I've only ever found one case where FSO
    > could do something that I couldn't do using VBA and/or API calls (the
    > ability to get the LastUpdated date for a folder)
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no private e-mails, please)
    >
    >
    > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > news:eDT%23%23hfdGHA.1260@TK2MSFTNGP05.phx.gbl...
    >> Nevermind, was missing the Scripting runtime reference.
    >>
    >> Doh!
    >>
    >> ;-D
    >>
    >> "SusanV" <svanallen@nospam-mvps.org> wrote in message
    >> news:%23IFXDffdGHA.3900@TK2MSFTNGP05.phx.gbl...
    >>> Hi all,
    >>>
    >>> Access 2000, I'm trying to use a code sample to parse the contents of a
    >>> directory, but am getting a compile error on
    >>>
    >>> Dim fso As FileSystemObject
    >>>
    >>> Do I need to set a specific reference to use a FileSystemObject??? I've
    >>> wasted a good hour searching the web and none of the snippets or samples
    >>> mention setting any kind of reference.
    >>>
    >>> TIA,
    >>>
    >>> SusanV
    >>>

    >>
    >>

    >
    >
     
  6. SusanV

    SusanV
    Expand Collapse
    Guest

    Hey Phil!

    Long time no see - hope all is well with you and yours! Thanks for the
    links - I'm sure they'll be helpful!

    ;-)

    SusanV

    "Phillip Windell" <@.> wrote in message
    news:evwws2fdGHA.2068@TK2MSFTNGP02.phx.gbl...
    > Hoowwdy stranger!
    >
    > I did these two scripts a couple years ago. They were used in ASP to scan
    > through files in a folder on a website then look inside the files for
    > specific things ("Include file" references). But the main thing is that
    > they do the file/folder recursion and that part of the code should be the
    > same.
    >
    > http://darkfalz.com/scripts_details.aspx?pstid=1081
    > http://darkfalz.com/scripts_details.aspx?pstid=1084
    >
    >
    > --
    > Phillip Windell [MCP, MVP, CCNA]
    > www.wandtv.com
    >
    >
    >
    > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > news:eDT%23%23hfdGHA.1260@TK2MSFTNGP05.phx.gbl...
    >> Nevermind, was missing the Scripting runtime reference.
    >>
    >> Doh!
    >>
    >> ;-D
    >>
    >> "SusanV" <svanallen@nospam-mvps.org> wrote in message
    >> news:%23IFXDffdGHA.3900@TK2MSFTNGP05.phx.gbl...
    >> > Hi all,
    >> >
    >> > Access 2000, I'm trying to use a code sample to parse the contents of a
    >> > directory, but am getting a compile error on
    >> >
    >> > Dim fso As FileSystemObject
    >> >
    >> > Do I need to set a specific reference to use a FileSystemObject??? I've
    >> > wasted a good hour searching the web and none of the snippets or
    >> > samples
    >> > mention setting any kind of reference.
    >> >
    >> > TIA,
    >> >
    >> > SusanV
    >> >

    >>
    >>

    >
    >
     
  7. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    It's not intuitive, but yes, Dir can do what you're looking to do.

    You need to code a recursive routine. Since you can't nest Dir calls, you
    need to store the subfolders in a collection (or an array), and then process
    each subfolder once you're done with the files of the parent.


    Public Sub ListFilesUsingDir( _
    StartDir As String, _
    FileList As Collection _
    )

    Dim strFile As String
    Dim strFolder As String
    Dim strSubfolder As String
    Dim varFolder As Variant
    Dim colSubfolders As Collection

    ' Ensure the starting folder is
    ' correctly formatted
    strFolder = QualifyFolderPath(StartDir)
    If Len(strFolder) > 0 Then

    ' Add each of the files in the folder
    ' to the Collection
    strFile = Dir$(strFolder & "*.*")
    Do While Len(strFile) > 0
    FileList.Add strFolder & strFile
    strFile = Dir$
    Loop

    ' Build a list of subfolders in the folder,
    ' adding each one to a local collection
    Set colSubfolders = New Collection
    strSubfolder = Dir$(strFolder, vbDirectory)
    Do While Len(strSubfolder) > 0
    If (strSubfolder <> ".") And _
    (strSubfolder <> "..") Then
    If (GetAttr(strFolder & strSubfolder) _
    And vbDirectory) = vbDirectory Then
    strSubfolder = strFolder & strSubfolder
    colSubfolders.Add strSubfolder
    End If
    End If
    strSubfolder = Dir$
    Loop

    ' Process each subfolder found above recursively
    ' Note that you must use a variant when
    ' enumerating the elements of a collection,
    ' but our function is expecting a string.
    For Each varFolder In colSubfolders
    strFolder = varFolder
    Call FilesUsingDir(strFolder, FileList)
    Next varFolder
    End If

    End Sub

    You'd call this routine using code similar to:

    Public Sub dirTest()
    Dim colFileList As Collection
    Dim intLoop As Integer
    Dim strStartDir As String
    Dim strMessage As String

    strStartDir = "C:\"

    Set colFileList = New Collection
    Call ListFilesUsingDir( _
    strStartDir, colFileList)
    If colFileList.Count = 1 Then
    strMessage = "There is 1 file under "
    Else
    strMessage = "There are " & _
    colFileList.Count & " files under "
    End If
    strMessage = strMessage & strStartDir
    Debug.Print strMessage
    For intLoop = 1 To colFileList.Count
    Debug.Print colFileList(intLoop)
    Next intLoop
    Debug.Print
    Set colFileList = Nothing

    End Sub

    QualifyFolderPath, referred to in ListFilesUsingDir above, is simply a
    helper function I use to ensure that the folder name ends in a slash:

    Function QualifyFolderPath(PathName As String) _
    As String

    If Len(PathName) > 0 Then
    If Right$(PathName, 1) <> "\" Then
    QualifyFolderPath = PathName & "\"
    Else
    QualifyFolderPath = PathName
    End If
    Else
    QualifyFolderPath = ""
    End If

    End Function



    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "SusanV" <svanallen@nospam-mvps.org> wrote in message
    news:ePtWlLBeGHA.3484@TK2MSFTNGP04.phx.gbl...
    > Good Morning Doug,
    >
    > What I'm trying to do is populate a table based on the filenames found in

    a
    > directory tree, then (hopefully) create a search form so users can find
    > these files. Files are added (and sometimes moved) by other folks, and we
    > don't have control over the directory - and it's driving my guys nuts

    trying
    > to locate stuff.
    >
    > Perhaps there is an easier way - but using VBA's Dir function doesn't seem
    > to return subfolder contents, as does fso - is there some switch or syntax
    > I'm missing?
    >
    > TIA,
    >
    > Susan
    >
    > "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    > news:O0uTsBgdGHA.1260@TK2MSFTNGP05.phx.gbl...
    > > Are you sure you need to use FSO? I've only ever found one case where

    FSO
    > > could do something that I couldn't do using VBA and/or API calls (the
    > > ability to get the LastUpdated date for a folder)
    > >
    > > --
    > > Doug Steele, Microsoft Access MVP
    > > http://I.Am/DougSteele
    > > (no private e-mails, please)
    > >
    > >
    > > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > > news:eDT%23%23hfdGHA.1260@TK2MSFTNGP05.phx.gbl...
    > >> Nevermind, was missing the Scripting runtime reference.
    > >>
    > >> Doh!
    > >>
    > >> ;-D
    > >>
    > >> "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > >> news:%23IFXDffdGHA.3900@TK2MSFTNGP05.phx.gbl...
    > >>> Hi all,
    > >>>
    > >>> Access 2000, I'm trying to use a code sample to parse the contents of

    a
    > >>> directory, but am getting a compile error on
    > >>>
    > >>> Dim fso As FileSystemObject
    > >>>
    > >>> Do I need to set a specific reference to use a FileSystemObject???

    I've
    > >>> wasted a good hour searching the web and none of the snippets or

    samples
    > >>> mention setting any kind of reference.
    > >>>
    > >>> TIA,
    > >>>
    > >>> SusanV
    > >>>
    > >>
    > >>

    > >
    > >

    >
    >
     
  8. SusanV

    SusanV
    Expand Collapse
    Guest

    Wow, thanks Doug! Now to wrap my brain around whatall the code is doing
    <grin>

    You rock!

    "Douglas J Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    news:OJQgaNDeGHA.4932@TK2MSFTNGP03.phx.gbl...
    > It's not intuitive, but yes, Dir can do what you're looking to do.
    >
    > You need to code a recursive routine. Since you can't nest Dir calls, you
    > need to store the subfolders in a collection (or an array), and then
    > process
    > each subfolder once you're done with the files of the parent.
    >
    >
    > Public Sub ListFilesUsingDir( _
    > StartDir As String, _
    > FileList As Collection _
    > )
    >
    > Dim strFile As String
    > Dim strFolder As String
    > Dim strSubfolder As String
    > Dim varFolder As Variant
    > Dim colSubfolders As Collection
    >
    > ' Ensure the starting folder is
    > ' correctly formatted
    > strFolder = QualifyFolderPath(StartDir)
    > If Len(strFolder) > 0 Then
    >
    > ' Add each of the files in the folder
    > ' to the Collection
    > strFile = Dir$(strFolder & "*.*")
    > Do While Len(strFile) > 0
    > FileList.Add strFolder & strFile
    > strFile = Dir$
    > Loop
    >
    > ' Build a list of subfolders in the folder,
    > ' adding each one to a local collection
    > Set colSubfolders = New Collection
    > strSubfolder = Dir$(strFolder, vbDirectory)
    > Do While Len(strSubfolder) > 0
    > If (strSubfolder <> ".") And _
    > (strSubfolder <> "..") Then
    > If (GetAttr(strFolder & strSubfolder) _
    > And vbDirectory) = vbDirectory Then
    > strSubfolder = strFolder & strSubfolder
    > colSubfolders.Add strSubfolder
    > End If
    > End If
    > strSubfolder = Dir$
    > Loop
    >
    > ' Process each subfolder found above recursively
    > ' Note that you must use a variant when
    > ' enumerating the elements of a collection,
    > ' but our function is expecting a string.
    > For Each varFolder In colSubfolders
    > strFolder = varFolder
    > Call FilesUsingDir(strFolder, FileList)
    > Next varFolder
    > End If
    >
    > End Sub
    >
    > You'd call this routine using code similar to:
    >
    > Public Sub dirTest()
    > Dim colFileList As Collection
    > Dim intLoop As Integer
    > Dim strStartDir As String
    > Dim strMessage As String
    >
    > strStartDir = "C:\"
    >
    > Set colFileList = New Collection
    > Call ListFilesUsingDir( _
    > strStartDir, colFileList)
    > If colFileList.Count = 1 Then
    > strMessage = "There is 1 file under "
    > Else
    > strMessage = "There are " & _
    > colFileList.Count & " files under "
    > End If
    > strMessage = strMessage & strStartDir
    > Debug.Print strMessage
    > For intLoop = 1 To colFileList.Count
    > Debug.Print colFileList(intLoop)
    > Next intLoop
    > Debug.Print
    > Set colFileList = Nothing
    >
    > End Sub
    >
    > QualifyFolderPath, referred to in ListFilesUsingDir above, is simply a
    > helper function I use to ensure that the folder name ends in a slash:
    >
    > Function QualifyFolderPath(PathName As String) _
    > As String
    >
    > If Len(PathName) > 0 Then
    > If Right$(PathName, 1) <> "\" Then
    > QualifyFolderPath = PathName & "\"
    > Else
    > QualifyFolderPath = PathName
    > End If
    > Else
    > QualifyFolderPath = ""
    > End If
    >
    > End Function
    >
    >
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    > news:ePtWlLBeGHA.3484@TK2MSFTNGP04.phx.gbl...
    >> Good Morning Doug,
    >>
    >> What I'm trying to do is populate a table based on the filenames found in

    > a
    >> directory tree, then (hopefully) create a search form so users can find
    >> these files. Files are added (and sometimes moved) by other folks, and we
    >> don't have control over the directory - and it's driving my guys nuts

    > trying
    >> to locate stuff.
    >>
    >> Perhaps there is an easier way - but using VBA's Dir function doesn't
    >> seem
    >> to return subfolder contents, as does fso - is there some switch or
    >> syntax
    >> I'm missing?
    >>
    >> TIA,
    >>
    >> Susan
    >>
    >> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    >> news:O0uTsBgdGHA.1260@TK2MSFTNGP05.phx.gbl...
    >> > Are you sure you need to use FSO? I've only ever found one case where

    > FSO
    >> > could do something that I couldn't do using VBA and/or API calls (the
    >> > ability to get the LastUpdated date for a folder)
    >> >
    >> > --
    >> > Doug Steele, Microsoft Access MVP
    >> > http://I.Am/DougSteele
    >> > (no private e-mails, please)
    >> >
    >> >
    >> > "SusanV" <svanallen@nospam-mvps.org> wrote in message
    >> > news:eDT%23%23hfdGHA.1260@TK2MSFTNGP05.phx.gbl...
    >> >> Nevermind, was missing the Scripting runtime reference.
    >> >>
    >> >> Doh!
    >> >>
    >> >> ;-D
    >> >>
    >> >> "SusanV" <svanallen@nospam-mvps.org> wrote in message
    >> >> news:%23IFXDffdGHA.3900@TK2MSFTNGP05.phx.gbl...
    >> >>> Hi all,
    >> >>>
    >> >>> Access 2000, I'm trying to use a code sample to parse the contents of

    > a
    >> >>> directory, but am getting a compile error on
    >> >>>
    >> >>> Dim fso As FileSystemObject
    >> >>>
    >> >>> Do I need to set a specific reference to use a FileSystemObject???

    > I've
    >> >>> wasted a good hour searching the web and none of the snippets or

    > samples
    >> >>> mention setting any kind of reference.
    >> >>>
    >> >>> TIA,
    >> >>>
    >> >>> SusanV
    >> >>>
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     

Share This Page