.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get all files from directory

Posted By:abhays       Posted Date: October 15, 2014    Points: 40    Category: Collections    URL: http://www.dotnetspark.com  

Below code block explains how to get all files of a paricular type(pdf,text,xml etc.) from directory

private string[] pdfFiles = GetFileNames("C:\\PDFFiles", *.pdf");

private static string[] GetFileNames(string path, string filter)
    string[] files = Directory.GetFiles(path, filter);
    for(int i = 0; i < files.Length; i++)
        files[i] = Path.GetFileName(files[i]);
    return files;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend