schangxiang@126.com
2024-08-26 19036333fec441fa79f7865691d85a9e545e29b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
namespace iWare_SCADA_BusinessLogical.Utils
{
    /// <summary>
    /// 文件夹帮助
    /// </summary>
    public class FolderHelper
    {
        /// <summary>
        /// 获取某文件夹的所有子目录
        /// </summary>
        /// <param name="folderPath"></param>
        /// <returns></returns>
        public static DirectoryInfo[] GetDirectories(string folderPath)
        {
            DirectoryInfo mainFolder = new DirectoryInfo(folderPath);
            //找到该文件夹下的子目录
            return mainFolder.GetDirectories();
        }
 
        /// <summary>
        /// 列出path路径对应的文件夹中的子文件夹和文件
        /// 然后再递归列出子文件夹内的文件夹
        /// </summary>
        /// <param name="path">需要列出内容的文件夹的路径</param>
        /// <param name="leval">当前递归层级,用于控制输出前导空格的数量,从0开始</param>
        public static void ListDirectory(string path, int leval, ref List<string> findFolderList)
        {
            DirectoryInfo theFolder = new DirectoryInfo(@path);
            findFolderList.Add(theFolder.FullName);
            leval++;
 
            //遍历文件
            foreach (FileInfo NextFile in theFolder.GetFiles())
            {
 
            }
 
            //遍历文件夹
            foreach (DirectoryInfo NextFolder in theFolder.GetDirectories())
            {
                findFolderList.Add(NextFolder.FullName);
                ListDirectory(NextFolder.FullName, leval, ref findFolderList);
            }
        }
    }
}