Beispiel #1
0
        public static void ClearFilesSkipExtend(string inDir, string extend)
        {
            DirectoryInfo TargetDir = new DirectoryInfo(inDir);

            DirectoryInfo[] SubDirs  = TargetDir.GetDirectories();
            FileInfo[]      SubFiles = TargetDir.GetFiles();

            foreach (var SubDir in SubDirs)
            {
                ClearPath(SubDir.FullName, true);
            }
            foreach (var SubFile in SubFiles)
            {
                if (SubFile.Name.EndsWith(extend))
                {
                    continue;
                }
                SubFile.Delete();
            }
        }
Beispiel #2
0
        /// @Brief	: 清空目录下的所有文件/文件夹
        /// @Param	: InDir			指定的目录
        /// @Param	: InDeleteSelf	是否删除自己(目录本身)
        /// @Param	: NONE
        public static void ClearPath(string InDir, bool InDeleteSelf)
        {
            DirectoryInfo TargetDir = new DirectoryInfo(InDir);

            DirectoryInfo[] SubDirs  = TargetDir.GetDirectories();
            FileInfo[]      SubFiles = TargetDir.GetFiles();

            foreach (var SubDir in SubDirs)
            {
                ClearPath(SubDir.FullName, true);
            }
            foreach (var SubFile in SubFiles)
            {
                SubFile.Delete();
            }

            if (InDeleteSelf)
            {
                TargetDir.Delete();
            }
        }