What are all the ways to traverse directory trees?

后端 未结 7 1041
挽巷
挽巷 2021-01-02 04:13

How do you traverse a directory tree in your favorite language?

What do you need to know to traverse a directory tree in different operating systems? On different f

相关标签:
7条回答
  • 2021-01-02 04:40

    In C#:

    Stack<DirectoryInfo> dirs = new Stack<DirectoryInfo>();
    
    dirs.Push(new DirectoryInfo("C:\\"));
    
    while (dirs.Count > 0) {
        DirectoryInfo current = dirs.Pop();
    
        // Do something with 'current' (if you want)
    
        Array.ForEach(current.GetFiles(), delegate(FileInfo f)
        {
            // Do something with 'f'
        });
    
        Array.ForEach(current.GetDirectories(), delegate(DirectoryInfo d)
        {
            dirs.Push(d);
        });
    }
    
    0 讨论(0)
提交回复
热议问题