Print Folder, Subfolder and File Name in excel file

Hi,
I have a hierarchy of folder structure -
Example :

  1. C:\Users\abc\Documents\Audit Drivers\Audit\ALL DA LIST\DBH1\Sunny\Invoice\2021\filename.pdf
  2. C:\Users\abc\Documents\Audit Drivers\Audit\ALL DA LIST\DBH1\Sunny\Invoice\2022\filename.pdf
  3. C:\Users\abc\Documents\Audit Drivers\Audit\ALL DA LIST\DBH1\Sunny\PCN Documents\Week 1\filename.pdf

and many more…
Parent folder : C:\Users\abc\Documents\Audit Drivers\Audit\ALL DA LIST

What I want to do is print the name of subfolders and filename inside this parent folder in an excel file

In this format -
image

Each level being the column of each subfolder and level 5 being the filename

Any insights/ suggestion would be highly appreciated
Thanks,
Sunny

Hi @Sunny_Jha ,

Could you give this a try?

image

image
image

str_parentDirectory = "C:\Users\abc\Documents\Audit Drivers\Audit\ALL DA LIST"
Directory.GetDirectories(str_parentDirectory,"*",SearchOption.AllDirectories).
	SelectMany(Function(s) Directory.GetFiles(s.ToString)).
	Select(Function(s) s.ToString.Replace(str_parentDirectory+"\","")).
	ToArray()

OutputFolderDirectoryToExcel.xaml (9.2 KB)

Kind Regards,
Ashwin A.K

Thanks for your help! :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.