有个文件夹是只读的,里面的文件也是只读的,现在想删除这个文件夹,并删除里面的文件new FileInfo(DirName).IsReadOnly = false;
或者
new FileInfo(DirName).Attributes = FileAttributes.Normal;现在用上面的两个函数,再调用Directory.Delete(DirName, true);
还是抛出"xxxx文件拒绝访问"异常,怎么解决?
或者
new FileInfo(DirName).Attributes = FileAttributes.Normal;现在用上面的两个函数,再调用Directory.Delete(DirName, true);
还是抛出"xxxx文件拒绝访问"异常,怎么解决?
解决方案 »
- IDataReader 数据库相关 问题
- Console.Write(ds.table[2].Rows[0][1].ToString();什么意思
- excel导入到sqlserver错误
- 如何从数据库中读出图片并反应在pictureBox里?
- 如何实现拖动窗体和拖动任务栏一样?
- 请问:在sqlserver写存储过程的时候,你们游标用的多吗?
- 怎样将DateTimePicker绑定于DataGrid里面啊???
- 求助:画椭圆的方法
- GetActiveWindow只有取自己窗口的句柄?
- 我建了个群:2282141 C#的加吧
- DataGridView绑定记录集后,如何清空里面数据
- C# 多个timer后出现问题
(new FileInfo(@"E:\001.txt")).IsReadOnly = false;
现在问题是:现在只能遍历文件,然后去掉文件的只读属性,删掉文件,然后再删掉目录,
有没有一劳永逸的方法:一次性删除文件和文件夹,就像 rd /S /D xxx 这个命令一样干脆利索。。
public void Cmdshutdown(string cmdstr)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmdstr);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
p.WaitForExit(); }