.Net文件操作--赋值、粘贴、删除

来源:互联网 发布:Matlab数据精度 编辑:程序博客网 时间:2024/06/05 20:18
1、.net删除文件或者文件夹(文件夹以"\"结尾)   
    public static bool FilePicDelete(string path)
    {
        bool ret = false;
        System.IO.FileInfo file = new System.IO.FileInfo(path);
        if (file.Exists)
        {
            file.Delete();
            ret = true;
        }
        return ret;
    }
2、.net复制文件
  public void copyFile(string ObjectFile,String SourceFile )
    {
        string sourceFile = Server.MapPath(SourceFile);
        string objectFile = Server.MapPath(ObjectFile);
        if (System.IO.File.Exists(sourceFile))
        {
            System.IO.File.Copy(sourceFile, objectFile, true);
        }
    }
3、.net创建文件夹
 private void createFolder(string path)
    {
        if (!Directory.Exists(Server.MapPath(path)))
            Directory.CreateDirectory(Server.MapPath(path));
    }
原创粉丝点击