Recursively get all files and folders under the specified drive letter

Source: Internet
Author: User

<summary>
Recursively get all files and folders under the specified drive letter
There is a partial folder access permission issue
</summary>
<param name= "path" >string path = @ "G:\"; </param>
<param name= "Filter" >string filter = "*.mp3";</param>
  1. private static void Parsedirectory (string path, String filter)
  2. {
  3. Get all folder paths under directory
  4. string[] dirs = directory.getdirectories (path);
  5. if (dirs. Length = = 0)
  6. Return
  7. IEnumerator iter = dirs. GetEnumerator ();
  8. Traverse folder path and file name under current path
  9. while (ITER. MoveNext ())
  10. {
  11. String str = (string) (ITER. Current);
  12. Parsedirectory (str, filter);
  13. }
  14. Gets the specified content in the specified folder
  15. string[] files = directory.getfiles (path, filter);
  16. if (Files. Length > 0)
  17. {
  18. M_pathlist.add (files);
  19. }
  20. }
  recursion (recursion): Programming skills that the program calls itself.

Recursion satisfies 2 conditions:

1) There is a process of repeated execution (call itself)

2) There are conditions for jumping out of the iterative process (recursive exit)

Recursively get all files and folders under the specified drive letter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.