Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2001
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select Directory and Subdirectory

    Hi all
    I am using the DSOFILE to update the properties of a number of files. My code uses a form to allow a user to select a directory and make alterations to the properties. This works well but now I need to process the files in the selected directory and all the subdirectories. I am unable to work out how to select and process the files in the subdirectories. Does anyone have a code snippet they could post or help me to create my own code

    Thanks

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select Directory and Subdirectory

    Might need more detail about what you are up to; however, have you examined the Dir() statement?

    You can easily iterate through a directory listing using Dir().

    You could also read the selected filenames into an array and process them that way.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    New Lounger
    Join Date
    Feb 2001
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select Directory and Subdirectory

    Hi Kevin
    I can select a directory and process all of the files in that directory, what I am trying to do is then move on to all of the subdirectories in that folder in turn and select and process those files.
    Once I have the directory I can deal with the files.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select Directory and Subdirectory

    Graham,

    I'm posting my poorly documented, and probably inefficient, code which I whipped up to serve one particular purpose., just in case it's of use. Sorry about the lack of doco, it was never intended for anything more than a one-off which just kept hanging around.

    "SearchDirectory" is the main routine; this hardcodes the directory path below "c:temp".

    <pre>Option Explicit
    Dim mstrRoot As String
    Private sFileNames() As String
    Private sFileDir() As String
    Private dFileDateTime() As Date
    Dim lFileCount As Long
    Dim sSubDirList() As String
    Dim lSubDirCount As Long


    Private Sub Search(ByVal sPath As String)
    Dim sFileName As String
    Dim sFileTemp As String

    sFileName = Dir(sPath, vbDirectory)
    Do While sFileName <> ""
    If Not (GetAttr(sPath & sFileName) _
    And vbDirectory) = vbDirectory Then
    If sFileName <> "." And sFileName <> ".." Then
    sFileTemp = sFileName
    ReDim Preserve sFileNames(lFileCount)
    ReDim Preserve sFileDir(lFileCount)
    ReDim Preserve dFileDateTime(lFileCount)
    sFileNames(lFileCount) = sFileTemp
    sFileDir(lFileCount) = Replace(sPath, mstrRoot, "")
    dFileDateTime(lFileCount) = _
    FileDateTime(sPath & sFileName)
    lFileCount = lFileCount + 1
    End If
    End If
    sFileName = Dir ' Get next entry.
    Loop

    End Sub

    Private Sub BuildList(ByVal sPath As String)
    Dim sFileName As String
    sFileName = Dir(sPath, vbDirectory)
    Do While sFileName <> "" '
    If (GetAttr(sPath & sFileName) And vbDirectory) = vbDirectory Then
    If sFileName <> "." And sFileName <> ".." Then
    lSubDirCount = lSubDirCount + 1
    ReDim Preserve sSubDirList(lSubDirCount)
    sSubDirList(lSubDirCount) = sPath & sFileName & ""
    End If
    End If
    sFileName = Dir ' Get next entry.
    Loop
    End Sub


    Private Sub SearchDirectory()
    Dim i As Long
    Dim sPath As String
    Dim sTemp As String
    sPath = "c:temp"

    ReDim sSubDirList(0)
    sSubDirList(0) = sPath
    lSubDirCount = 0
    Call BuildList(sPath)
    i = 0
    Do Until i >= lSubDirCount
    i = i + 1
    Call BuildList(sSubDirList(i))
    Loop
    i = 0
    Do Until i >= lSubDirCount - 1
    i = i + 1
    If sSubDirList(i) > sSubDirList(i + 1) Then
    sTemp = sSubDirList(i)
    sSubDirList(i) = sSubDirList(i + 1)
    sSubDirList(i + 1) = sTemp
    i = 0
    End If
    Loop
    For i = 0 To lSubDirCount
    Call Search(sSubDirList(i))
    Next
    End Sub
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    New Lounger
    Join Date
    Feb 2001
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select Directory and Subdirectory

    Geoff
    Thanks for your post I will have a look at it and see if I can figure it out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •