Example #1
0
        //获取某一个文件夹下所有文件的链表
        public void GetFileFolderListFromFolder(string path, List <FileFolderInfoNode> all_filefolder)
        {
            Queue <FileFolderInfoNode> temp_folder = new Queue <FileFolderInfoNode>();
            FileFolderInfoNode         temp        = new FileFolderInfoNode();

            temp.type        = OverAllData.FILETYPE_FOLDER;
            temp.folder_info = new DirectoryInfo(path);
            all_filefolder.Add(temp);
            temp_folder.Enqueue(temp);
            while (temp_folder.Count != 0)
            {
                FileFolderInfoNode fn = temp_folder.Dequeue();
                foreach (DirectoryInfo di in fn.folder_info.GetDirectories())
                {
                    FileFolderInfoNode fn_t = new FileFolderInfoNode();
                    fn_t.type        = OverAllData.FILETYPE_FOLDER;
                    fn_t.folder_info = new DirectoryInfo(di.FullName);
                    all_filefolder.Add(fn_t);
                    temp_folder.Enqueue(fn_t);
                }
                foreach (FileInfo fi in fn.folder_info.GetFiles())
                {
                    FileFolderInfoNode fn_t = new FileFolderInfoNode();
                    fn_t.type      = OverAllData.FILETYPE_FILE;
                    fn_t.file_info = new FileInfo(fi.FullName);
                    all_filefolder.Add(fn_t);
                }
            }
        }
Example #2
0
        //统计一个文件夹中的所有子文件及子文件夹数量
        public void CountAllFileAndFolderNum(string path, out int file_num, out int folder_num)
        {
            Queue <FileFolderInfoNode> temp_folder = new Queue <FileFolderInfoNode>();
            FileFolderInfoNode         temp        = new FileFolderInfoNode();

            temp.type        = OverAllData.FILETYPE_FOLDER;
            temp.folder_info = new DirectoryInfo(path);
            temp_folder.Enqueue(temp);
            folder_num = 1;
            file_num   = 0;
            while (temp_folder.Count != 0)
            {
                FileFolderInfoNode fn = temp_folder.Dequeue();
                foreach (DirectoryInfo di in fn.folder_info.GetDirectories())
                {
                    FileFolderInfoNode fn_t = new FileFolderInfoNode();
                    fn_t.type        = OverAllData.FILETYPE_FOLDER;
                    fn_t.folder_info = new DirectoryInfo(di.FullName);
                    temp_folder.Enqueue(fn_t);
                    folder_num++;
                }
                file_num += fn.folder_info.GetFiles().Length;
            }
        }