CleanUp() 공개 정적인 메소드

public static CleanUp ( string path ) : void
path string
리턴 void
예제 #1
0
        public static bool Delete(string path)
        {
            if (path == null)
            {
                return(false);
            }

            string dirRoot = Path.GetDirectoryName(path);
            string pattern = Path.GetFileName(path);

            // directory
            if (IsDirectory(path))
            {
                DirectoryHelper.CleanUp(path);
                return(true);
            }

            // wild-card char
            if (path.IndexOf("*", StringComparison.Ordinal) >= 0)
            {
                if (pattern != null && dirRoot != null)
                {
                    string[] fileList = Directory.GetFileSystemEntries(dirRoot, pattern, SearchOption.TopDirectoryOnly);
                    foreach (string file in fileList)
                    {
                        if (IsDirectory(file))
                        {
                            //it's a directory
                            Directory.Delete(file, true);
                        }
                        else
                        {
                            // we can before, we want to avoid deleting an already deleted file in sub-directory
                            File.Delete(file);
                        }
                    }
                }
            }
            else
            {
                // single file delete
                File.Delete(path);
            }

            return(true);
        }
예제 #2
0
        public static bool Delete(string path)
        {
            if (path == null)
            {
                return(false);
            }

            var dirRoot = Path.GetDirectoryName(path);
            var pattern = Path.GetFileName(path);

            // directory
            if (IsDirectory(path))
            {
                DirectoryHelper.CleanUp(path);
                return(true);
            }

            // wild-card char
            if (path.IndexOf("*", StringComparison.Ordinal) >= 0)
            {
                if (dirRoot != null)
                {
                    var fileList = Directory.GetFileSystemEntries(dirRoot, pattern, SearchOption.TopDirectoryOnly);
                    foreach (string file in fileList)
                    {
                        DeletePath(file);
                    }
                }
            }
            else
            {
                // single file delete
                File.Delete(path);
            }

            return(true);
        }