How can I perform full recursive directory & file scan?

后端 未结 6 1188
囚心锁ツ
囚心锁ツ 2020-12-11 01:38

here is my code:

    private static void TreeScan(string sDir)
    {
        foreach (string d in Directory.GetDirectories(sDir))
        {
            forea         


        
6条回答
  •  独厮守ぢ
    2020-12-11 02:14

    Your GetFiles loop should be outside the GetDirectories loop. And shouldn't your TreeScan stay inside GetDirectories loop? In short the code should look like this:

    private static void TreeScan(string sDir)
    {
        foreach (string d in Directory.GetDirectories(sDir))
        {
            TreeScan(d, client);
        }
        foreach (string f in Directory.GetFiles(d))
        {
            //Save file f
        }
    }
    

提交回复
热议问题