访问路径拒绝错误

时间:2016-08-03 15:40:07

标签: c#

我有一个程序需要删除完整目录,但我收到private void timer1_Tick(object sender, EventArgs e) { label1.Text = DateTime.Now.ToString("HH:mm"); string lowDir = ""; if (label1.Text == comboBox1.Text) { try { if (System.IO.Directory.GetDirectories(txpath1.Text).Length != 0) { try { var folders = Directory.GetDirectories(@"" + txpath1.Text); DateTime lastLow = DateTime.Now; foreach (string subdir in Directory.GetDirectories(@"" + txpath1.Text)) { DirectoryInfo fi1 = new DirectoryInfo(subdir); fi1.Refresh(); DateTime created = fi1.LastWriteTime; if (created < lastLow) { lowDir = subdir; lastLow = created; } } var dir = new DirectoryInfo(@"" + lowDir); Directory.Delete(@"" + lowDir, true); } catch (Exception ex) { this.btStop.PerformClick(); MessageBox.Show(ex.Message+"\nEzért a program leállt."); } finally { timer1.Stop(); timer2.Start(); } } else { this.btStop.PerformClick(); MessageBox.Show("A megadott elérési útvonalon nem találhatóak fájlok a művelet(ek)hez!"); } } catch (DirectoryNotFoundException) { btStop.PerformClick(); MessageBox.Show("Hibás útvonala(kat)t adtál meg!"); } } } 错误。我完全可以访问所有人,但它没有帮助。

In [95]:
df2.rename(columns={df2.columns[-1]:'newName'}, inplace=True)
df2

Out[95]:
   1  2  newName
0  4  4        5
1  1  2        7
2  3  1        9
3  1  4        1

1 个答案:

答案 0 :(得分:0)

您只需要使用Directory.Delete(path, true)递归删除。如果这不起作用,则很可能是一条畸形的道路。