• 删除文件夹及文件的操作方法(记下,以备后用)


    呵呵,把两个程序写下来备查~       

     

            /// <summary>
            /// 清空指定的文件夹,但不删除文件夹
            /// </summary>
            /// <param name="dir"></param>
            public static void DeleteFolder(string dir)
            {
                foreach (string d in Directory.GetFileSystemEntries(dir))
                {
                    if (File.Exists(d))
                    {
                        FileInfo fi = new FileInfo(d);
                        if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                            fi.Attributes = FileAttributes.Normal;
                        File.Delete(d);//直接删除其中的文件  
                    }
                    else
                    {
                        DirectoryInfo d1 = new DirectoryInfo(d);
                        if (d1.GetFiles().Length != 0)
                        {
                            DeleteFolder(d1.FullName);////递归删除子文件夹
                        }
                        Directory.Delete(d);
                    }
                }
            }

            /// <summary>
            /// 删除文件夹及其内容
            /// </summary>
            /// <param name="dir"></param>
            public static void DeleteFolder1(string dir)
            {
                foreach (string d in Directory.GetFileSystemEntries(dir))
                {
                    if (File.Exists(d))
                    {
                        FileInfo fi = new FileInfo(d);
                        if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                            fi.Attributes = FileAttributes.Normal;
                        File.Delete(d);//直接删除其中的文件  
                    }
                    else
                        DeleteFolder(d);////递归删除子文件夹
                    Directory.Delete(d);
                }
            }

  • 相关阅读:
    Flex弹性布局在移动设备上的应用
    移动端页面开发问题总结
    js中的this关键字详解
    require.js 入门学习 (share)
    jQuery自定义滚动条样式插件mCustomScrollbar
    js中继承的几种用法总结(apply,call,prototype)
    js正则表达式
    js判断访问来源
    javascript 函数及作用域总结介绍
    javascript深入理解js闭包
  • 原文地址:https://www.cnblogs.com/lujin49/p/2130060.html
Copyright © 2020-2023  润新知