Create Directorys based on table paths

chris-uk-lad

Registered User.
Local time
Today, 00:38
Joined
Jul 8, 2008
Messages
271
Hi all,

I have a table at current that has various lines containing file paths which i want to manipulate with VB. But i first want to copy all those files into the relevant folders (folders created in a new folder).

e.g of a file path.
Path FolderID FolderNum
C:\Work\ A1\ 1
C:\Work\ A2\ 1
C:\Work\ A2\ 2
C:\Work\ A2\ 3
C:\Work\ A3\ 1

I had before been using this code to create the initial directorys (A1/A2/A3 etc).
Code:
Set FileID = db.OpenRecordset("SELECT ALL [FolderID] FROM Table1 WHERE [FolderID] IS NOT NULL")
        
Do Until OMFileID.EOF
        MkDir strPath & "\" & FileID![FolderID]
jumpin:
        FileID.MoveNext
Loop

But dont know how to create the folders within these folders.
 
Use the API

Code:
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long

Place this in a public module then pass your entire path to the function. It will create all the folders and sub folders needed, if the path already exists it does nothing.
 
Ive interperated what you suggested as

Code:
    Do Until FileID.EOF
        MakeSureDirectoryPathExists (strFilePath)
        FileID.MoveNext
    Loop
 
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long
End Function

But i get an error so figure im doing wrong XD

"Only comments may appear after End Sub, End Function, or End Property"
 
Ive interperated what you suggested as

Code:
    Do Until FileID.EOF
        MakeSureDirectoryPathExists (strFilePath)
        FileID.MoveNext
    Loop
 
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long
End Function

But i get an error so figure im doing wrong XD

"Only comments may appear after End Sub, End Function, or End Property"

You cannot put the API declaration inside another function.

Code:
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long
 
Function YourFunction()
    Do Until FileID.EOF
        Call MakeSureDirectoryPathExists (strFilePath)
        FileID.MoveNext
    Loop
End Function
 
Hi -

You've failed to close this sub/function.
Code:
  Do Until FileID.EOF
        MakeSureDirectoryPathExists (strFilePath)
        FileID.MoveNext
    Loop
You can't incorporate the function in your sub/function. They must be separate.

HTH - Bob
 
Ive interperated what you suggested as

Code:
    Do Until FileID.EOF
        MakeSureDirectoryPathExists (strFilePath)
        FileID.MoveNext
    Loop
 
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long
End Function

But i get an error so figure im doing wrong XD

"Only comments may appear after End Sub, End Function, or End Property"
The line that says Public Declare Function goes in the General Declarations section at the very top of the module (just below the part that says Option Compare Database and below Option Explicit if you have that in there.
 
Thanks for all your input, because my lack of understanding i just nested a second recordset inside the the first, with several error handlers for error 75 (duplicate folder)
 

Users who are viewing this thread

Back
Top Bottom