Questions tagged [getdirectories]

Directory.GetDirectories is API method in C#

71 questions
163
votes
18 answers

List all files and directories in a directory + subdirectories

I want to list every file and directory contained in a directory and subdirectories of that directory. If I chose C:\ as the directory, the program would get every name of every file and folder on the hard drive that it had access to. A list might…
derp_in_mouth
  • 2,003
  • 4
  • 15
  • 17
14
votes
2 answers

Check if directory is accessible in C#?

Possible Duplicate: .NET - Check if directory is accessible without exception handling Im making a small file explorer in Visual Studio 2010 with NET 3.5 and C#, and I have this function to check if a directory is accessible: RealPath=@"c:\System…
user962284
  • 670
  • 1
  • 12
  • 29
9
votes
3 answers

How can I read the files in a directory in sorted order?

When I read a directory in Perl with opendir, readdir, and closedir, the readdir function doesn't seem to read the files in any specific order (that I can tell). I am reading a directory that has subdirectories named by epoch…
BrianH
  • 7,932
  • 10
  • 50
  • 71
6
votes
3 answers

Is the order of directories returned by Directory.GetDirectories() guaranteed to be ordered?

Although not mentioned in the documentation, Directory.GetDirectories() appears to always return a lexicographically-sorted array of directory names. Is it safe to rely on this implementation detail (it is suitable for my needs) or should I be…
Steve Guidi
  • 19,700
  • 9
  • 74
  • 90
6
votes
4 answers

DirectoryInfo.GetDirectories() and attributes

I am using DirectoryInfo.GetDirectories() recursively to find the all the sub-directories under a given path. However, I want to exclude the System folders and there is no clear way for that. In FindFirstFile/FindNextFile things were clearer with…
Keeper
4
votes
2 answers

UnauthorizedAccessException with getDirectories

Hello everyone I currently got subdirectories I wanted through this call: foreach (DirectoryInfo dir in parent) { try { subDirectories = dir.GetDirectories().Where(d => d.Exists == true).ToArray(); } …
JPhillips
  • 59
  • 1
  • 5
4
votes
1 answer

Variation in performance when using GetDirectories

I have a production performance issue that I'm stumped on. I'm hoping that someone has seen something similar or at least has a few troubleshooting techniques. I support an inherited asp.net web application that retrieves files from a shared…
4
votes
2 answers

How to get latest file name from folder in directory

Ans: Here is one solution for getting latest file name from folder using c# code Call Function as follows: FileInfo newestFile = GetNewestFile(new DirectoryInfo(@"D:\DatabaseFiles")); Function: public static FileInfo GetNewestFile(DirectoryInfo…
Samad
  • 71
  • 2
  • 10
4
votes
2 answers

How to exclude folders when using Directory.GetDirectories

I want to return a list of all the subdirectories in the 'SomeFolder' directory excluding the 'Admin' and 'Templates' directories. I have the following folder structure (simplified): C:\inetpub\wwwroot\MyWebsite\SomeFolder\RandomString …
Dhaust
  • 5,470
  • 9
  • 54
  • 80
4
votes
2 answers

c# Directory.GetDirectories excluding folders

I'm trying to iterate through a list of users folders in windows in "c:\Users" but exclude the microsoft built-in user folders, the below is the code segment I'm using to accomplish this feat but it's for some reason not working as intended. private…
Clu
  • 339
  • 3
  • 8
  • 18
3
votes
2 answers

Can not access sub directories without '\' (backward slash) in C#

I had a bizarre situation when try to access the sub directories of my c: drive: first I tried the following code, the output was 0 (zero): MessageBox.Show(new DirectoryInfo("c:").GetDirectories().Length.ToString()); but when add '\' to path (c:),…
faz
  • 31
  • 1
3
votes
5 answers

Quicky estimate a number of subfolders

My C# 3.0 application should traverse through folders and do some stuff within. To show a meaningful progress, I need to know total folder count. If I use Directory.GetDirectories with AllDirectories option, this takes a very long time on my 2Tb…
Alex
  • 1,357
  • 3
  • 18
  • 41
3
votes
2 answers

c# GetDirectories returning unexpected directories (specific example given)

Using c# GetDirectories to retrieving folders immediately under the search directory. The code works for all other directories searched EXCEPT a single directory. Specifically, GetDirectories returns two different folders, one contains the search…
jpop1
  • 31
  • 1
  • 2
3
votes
3 answers

how to avoid unauthorized access exception?

The following is my code. //string[] directories; List dirs = new List(Directory.EnumerateDirectories("C:\\Users\\Josh")); //string[] Files; //directories = Directory.GetDirectories(@"C:\Users\Josh\", "*",…
2
votes
2 answers

C# treeview Unauthorized exception

So I followed MS article http://msdn.microsoft.com/en-us/library/ms171645.aspx This is Creating an Explorer Style Interface with the ListView and TreeView Controls Using the Designer. So all is well, howerver, is you set it to the root of C to scan…
user1158745
  • 2,402
  • 9
  • 41
  • 60
1
2 3 4 5