dobson
dobson

Reputation: 466

How to sort paths into two different categories - Is a file/Is a folder

When I refer to paths I am talking about directories/file paths (eg. - C:\Friends\noonelovesme.sql or C:\Friends)

I have a method that will ask you to choose a file or folder (You can select multiple files/folder). It will then add all of the files/folders you selected into a ListBox.

I want to be able to sort them so I know which are paths to a file and which are paths to a folder and then add them to string[]'s which will then allow me to the next steps of the program.

Basically all paths that have a file name at the end (c:\dog.txt) will be added to a string[] called IsFile & all paths that end with a folder will be added to a string[] called IsFolder.

I found this piece of code (for finding out if the path is for a file or folder):

FileAttributes attr = File.GetAttributes(@"c:\Temp");

if (attr.HasFlag(FileAttributes.Directory))
    MessageBox.Show("Its a directory");
else
    MessageBox.Show("Its a file");

But it seems to not accept arrays

Upvotes: 0

Views: 68

Answers (1)

dobson
dobson

Reputation: 466

Put everything inside of a foreach loop and just used an array for the dirs for folders/files.

Upvotes: 0

Related Questions