c# - 检查文件是否存在,存在则删除- 文件清理工具

  public static bool delFile(FileInfo file, string url)
        {
            try
            {
                if (file == null)
                {
                    file = new FileInfo(url);
                }

                if (!file.Exists)
                {
                    return true;
                }

                file.Delete();

                if (!new FileInfo(file.DirectoryName+"/"+file.Name).Exists)
                {
                    return true;
                }

                return false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return false;
            }
        }

 

posted @ 2023-03-09 14:08  岑惜  阅读(429)  评论(0)    收藏  举报