?
Solved

Help with folder recursion

Posted on 2002-04-12
6
Medium Priority
?
200 Views
Last Modified: 2010-08-05
Hi

I have a folder ie:
d:\folder1

it has both files and subfolders within it ie:
d:\folder1\subfolder1
d:\folder1\subfolder2

I want a function to rebuild the contents of d:\folder1 in d:\folder2
(Not a copy or move just create the folder/file- the content of the file is not important just the name)

Hope that is clear
0
Comment
Question by:SammyG
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6936368
quick and dirty:

dim objFSO as Object
dim objF as Object
set objFSO = CreateObject("Scripting.FileSystemObject")
set objF = objFSO.GetFolder ("D:\folder1")
objF.Copy "D:\folder2"

CHeers
0
 

Author Comment

by:SammyG
ID: 6936374
"(Not a copy or move just create the folder/file- the content of the file is not important just the name)"

I am not interested in the contents of each file just in re-creating the file structure.

Cheers,

S
0
 

Author Comment

by:SammyG
ID: 6936378
I am just come up with this. Any improvements?

text1 = "d:\folder1"
text2 = "d:\folder2"

Private Sub Command1_Click()
    CreateSC Text1, Text2
End Sub

Function CreateSC(ByVal pstrPath As String, ByVal pstrOutPath As String)

    Dim objFolder As Scripting.Folder
    Dim objFile As Scripting.File
    Dim objFS As New Scripting.FileSystemObject
    Dim objTS As Scripting.TextStream
    Dim objSubfolder As Scripting.Folder
    Dim strFolder As String
    Dim strFile As String
   
    Set objFolder = objFS.GetFolder(pstrPath)
   
    For Each objFile In objFolder.Files
           
        strFile = pstrOutPath & Replace(objFile, pstrPath, "", , , vbTextCompare)
        objFS.CreateTextFile strFile, True
       
    Next
   
    For Each objSubfolder In objFolder.SubFolders
       
        strFolder = pstrOutPath & Replace(objSubfolder, pstrPath, "", 1, , vbTextCompare)
        If Not objFS.FolderExists(strFolder) Then
            objFS.CreateFolder strFolder
        End If
        CreateSC objSubfolder, strFolder
       
    Next

End Function
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 140 total points
ID: 6936390
Ok, here we go :

Private Sub CopyFolder(source, destination)
  Dim objFSO As Object
  Dim objF As Object
   
  Set objFSO = CreateObject("Scripting.FileSystemObject")
 
  If Not IsObject(source) Then
    Set source = objFSO.GetFolder(source)
  End If
 
  If Not objFSO.FolderExists(destination) Then
    objFSO.CreateFolder (destination)
  End If
 
  For Each objF In source.Files
    objFSO.CreateTextFile destination & "\" & objF.Name
  Next
 
  For Each objF In source.SubFolders
    CopyFolder objF, destination & "\" & objF.Name
  Next
End Sub


Be aware that it doesn't contain any checks and error handling....

Usage:

CopyFolder "D:\folder1", "D:\folder2"

Cheers
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7754999
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to angelIII
Please leave any comments here within the
next seven days.
0
 

Expert Comment

by:SpideyMod
ID: 7812336
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question