Get folder names

Hi,

At this moment I am trying to get the names of several folder and put them into an array or datatable (preferred).

The case:

  1. i have a folder named: “case numbers”
  2. in this folder there are many folder with numbers, for instance folder name “123456”

I want to get all these names into a array or data table.
What can i use for this action?

Regards,
Ricky

Hi there @ricky.notenboom,
You can achieve this via:

arrMyArray = Directory.GetDirectories("Some Directory")

Which will return an array of strings, denoting the full file path of each folder.

If you only require the folder names, then you can do the following afterwards:

Assign - intCounter = 0
While intCounter < arrMyArray.Length

* Assign - arrMyArray(intCounter) = Path.GetFileName(arrMyArray(intCounter))
* Assign - intCounter = intCounter + 1

End While

Thanks,
Josh

3 Likes

Hi,

Here you go to get the all the folder names from particular directory.GetTheFolderNames.xaml (8.5 KB)

Use array of string variable to hold the all the file names and for each to get the name with full folder path:

ArrayFolder=directory.GetDirectories(“C:\Users\Giri\Desktop\caseNumber\Numbers”)

Thanks
Girish

2 Likes

Thanks @Mr_JDavey and @Girish!

Got it working!

Thanks for the good help.

Have a nice day!

1 Like

this video may help you

Hi Girish,

I have a requirement little bit next level from this.
Inside this folder “C:\Users\Giri\Desktop\caseNumber” – I will have many folders with different names.
In this I want to pick only the folders whose name starts with emp id(technically folder name with first seven digits should be numbers).

Eg:

1234567 - xxxxxx -----> Need to pick
ABC - xxxxx -------> Ignore
123 - xxxxx --------> Ignore
4567231 - xxxxxx -----> Need to pick
2345678 - xxxxxx -----> Need to pick

Please give your suggestions?

You can use the Linq statement Where and Regex to sort out foldes you do not want to process:

string path = ~
var dirNames = Directory.GetDirectories(path).Where(Func(p) Regex.IsMatch(p, "^\d{7}"))

This will get all directories in your path and filter them so you only have the ones that start with 7 digits.

Hi,

Thanks for your reply. I am getting validation error when i use the assignment statement you have given. If you don mind could you please check from your end and if it works please give me the .xaml.

I am struck with these, your inputs will be great help for me