Consulting

Results 1 to 5 of 5

Thread: folders and subfolders troubles

  1. #1

    Question folders and subfolders troubles

    hi all,
    i am trying to check a folder (purchase order) to see if some subfolders exist and if not, create them. i can create the folders with no problems whatsoever but am having a heck of time doing the check comparison. this is what i have so far and please excuse the hackiness of it:[VBA]Sub makefile()
    getdemofiles
    'Ck

    End Sub
    Function Ck()

    Dim strStartPath As String

    strStartPath = "C:\Documents and Settings\ERIK\Desktop\new folder" 'ENTER YOUR START FOLDER HERE
    ListFolder strStartPath

    End Function
    Function ListFolder(sFolderPath As String)

    Dim FS As New FileSystemObject
    Dim FSfolder As Folder
    Dim subfolder As Folder
    Dim i As Integer
    Dim w()
    Set FSfolder = FS.GetFolder(sFolderPath)

    For Each subfolder In FSfolder.SubFolders
    DoEvents
    i = i + 1
    Cells(i, 2) = subfolder
    ReDim Preserve w(1 To i)
    w(i) = subfolder
    Cells(i, 6) = w(i)
    Next subfolder
    ' If IsError(w(i)) Then Exit Function
    With Range("List")
    x = .Rows.count
    End With
    ChDir "C:\Documents and Settings\ERIK\Desktop\new folder"
    ReDim ary(x)
    For y = 1 To x
    ary(y) = Cells(y, "a").Value '///this=est sheet line items
    Range("c1") = ary(y) 'display array values
    MkDir ary(y)
    Next

    With Range("List1")
    x = .Rows.count
    ' For Z = 1 To x
    ' u = Range("list1").Cells.Address
    ' ary(Z) = Cells(Z, "a").Value '///this=est sheet line items
    ' Range("c1") = ary(Z) 'display array values
    ' MkDir ary(Z)
    ' Next
    End With
    Set FS = Nothing
    Set FSfolder = Nothing
    End Function
    Sub getdemofiles()
    Dim flist As Variant, str As String
    flist = getfiles("C:\Documents and Settings\ERIK\Desktop\new folder") '////(ThisWorkbook.Path)
    'If IsEmpty(flist) Then Exit Sub
    'Text.sortarray (flist)
    str = Join(flist, vbCrLf)
    Range("f1") = str
    End Sub
    Function getfiles(filepath As String) As Variant
    Dim arr() As String, fname As String, count As Integer
    fname = Dir(filepath & "\*")
    Do Until fname = ""
    count = count + 1
    ReDim Preserve arr(count)
    arr(count - 1) = fname
    fname = Dir()
    Loop
    getfiles = arr
    End Function[/VBA]
    i am not looking for code per se, but hints/clues ideas on how to approch this.
    thanks
    erik

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    There is a files collectin of folders

    [vba]
    For each file In subFolder.files

    'manipulate file object
    Next file
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    There is a files collectin of folders

    [vba]
    For each file In subFolder.files

    'manipulate file object
    Next file
    [/vba]
    thank you. know any good sources of info on the scripting?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    thank you xld.
    i appreciate the assistance.
    e

Posting Permissions

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