how to search files in folder including files in sub folder in c# RRS feed

  • Question

  • I need to scan files in some folder.

    In this folder, there are files and folders in which files or folder exists.

    I tried Directory.GetFiles() but it can not search files in the sub folder.

    How could I get all files in a folder? 

    • Edited by Jeff0803 Monday, April 23, 2018 10:50 PM
    Monday, April 23, 2018 10:34 PM

All replies

  • This works fine.

    string[] dirs = Directory.GetFiles(@ScanPath.Text, "*", SearchOption.AllDirectories);

    • Proposed as answer by Lee Liu Tuesday, April 24, 2018 6:08 AM
    Monday, April 23, 2018 10:53 PM
  • Hi Jeff0803,

    Thank you for posting here.

    If your question has been solved, please mark the useful reply as answer. This will make answer searching easier in the forum and be beneficial to community.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 24, 2018 6:47 AM