Question Using Directories, Sub-Directories and APIs

NiTRoX.NET

Member
Joined
Dec 21, 2006
Messages
6
Programming Experience
Beginner
Hi all,

Basically I'm going to try and develop a software that merges PDFs automatically using the PDFSharp API.

What I want in the program is to basically that:

  • Have the program to give and Input and Output directory
  • Merge all the documents in the directory or sub-directory
  • Rename the merged PDF file according the the name of the directory/sub-directory
  • If the folder has PDF files and a Sub-Directory I want to merge the PDF files in the folder and rename them as per the main folder, and rename the files in the sub-folder according to its name (i.e. seperate|)

It's the first time I'm using an API.

The problem I have is how to use the directories and sub-directories as I need them.

Any help on how to solve this problem?

Thanks & Regards,
BL
 
Directories in a file system form a tree structure, so the logical way to traverse them is using recursion. You can write a method that takes a folder path and the uses the Directory or DirectoryInfo class to get all the subfolders of that folder and calls itself for each one. That way, you visit every folder in the tree. What you then do with each folder is up to you.
Private Sub ProcessFolder(ByVal folderPath As String)
    'Process folder here.

    'Process all subfolders.
    For Each subfolderPath As String In IO.Directory.GetDirectories(folderPath)
        'Here is the recursive call.
        ProcessFolder(subfolderPath)
    Next
End Sub
 
Back
Top