TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dan
NA
23
8.5k
Adding string elements to List
Jun 29 2013 5:19 AM
Hello guys. I have an recursion function which opens me all directories from the path parameter, and gets all .pdf files. Instead of printing each file to the Console, I want to add it to a List<string> which is one of the function parameters.
This is my code:
private static void GetAllFilesFrom(string path, string extension)
{
try
{
if ((File.GetAttributes(path) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
{
foreach (string folder in Directory.GetDirectories(path))
{
foreach (string file in Directory.GetFiles(folder, extension))
{
Console.WriteLine(file);
}
GetAllFilesFrom(folder, extension);
}
}
}
catch (UnauthorizedAccessException) { }
}
Reply
Answers (
1
)
print a report
detail version of C#