Reputation: 1052
I have a directory structure something this:
parent
file1
file2
childFolder1
childFolder2
.
.
.
specialChildFolder
file3
file4
Basically I want to get a list of all the files in the parent
and specialChildFolder
. I did find this question C# Searching for files and folders except in certain folders which excludes particular child folders. There is only one child folder in my case that needs to be searched for files, so creating a long list of folders to be excluded seems backwards to me. It seems to me there should be a way to use a combination of Directory.GetFiles
and SearchOption.AllDirectories
to match the specific child directory, but I haven't been able to figure out the correct way to do that yet.
EDIT: The current code is:
string someFileLoc = Assembly.GetExecutingAssembly().Location;
string fileLocation = Path.GetDirectoryName(someFileLoc);
string[] files = Directory.GetFiles(fileLocation);
This currently gets the files from the parent folder (which is really bin), but not the child folder.
DISCLAIMER: I only have roughly a month of C# experience so this might be a painfully easy problem.
Upvotes: 1
Views: 1456
Reputation: 3523
Well, you can use recursion to test do perform a directory of the CURRENT folder and pass in a "level" parameter (int) which you reduce every time you call against a SUB folder. Only recurse further if the level is > 0. That way you can run it against any arbitary number of sub folders.
Can you provide the code you have so far and we can show you how to do this.
Upvotes: 1