PDA

View Full Version : folders and subfolders troubles



drawworkhome
11-27-2009, 04:43 PM
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: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
i am not looking for code per se, but hints/clues ideas on how to approch this.
thanks
erik

xld
11-28-2009, 03:41 AM
There is a files collectin of folders


For each file In subFolder.files

'manipulate file object
Next file

drawworkhome
11-28-2009, 07:36 AM
There is a files collectin of folders


For each file In subFolder.files

'manipulate file object
Next file

thank you. know any good sources of info on the scripting?

xld
11-28-2009, 09:15 AM
MSDN http://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx

drawworkhome
11-28-2009, 09:47 AM
thank you xld.
i appreciate the assistance.
e