Bizarre directory delete behaviour on SSD drive

前端 未结 6 737
遇见更好的自我
遇见更好的自我 2021-01-01 10:25

Directory c:\\test has 50 or so files in it, no subdirectories.

    If IO.Directory.Exists(\"C:\\test\") Then
        IO.Directory.Delete(\"C:\\test\", True)         


        
6条回答
  •  囚心锁ツ
    2021-01-01 11:20

    I've had problems with this before, but this is not specific to SSD drives. You would be far better off doing a move then delete:

    if(Directory.Exists(dirpath))
    {
        string temppath = dirpath + ".deleted";
        Directory.Move(dirpath, temppath);
        Directory.Delete(temppath, true);
    }
    Directory.Create(dirpath);
    

    The other way to deal with it is to loop until complete:

    if(Directory.Exists(dirpath))
    {
        Directory.Delete(dirpath, true);
        int limit = 100;
        while(Directory.Exists(dirpath) && limit-- > 0)
            Thread.Sleep(0);
    }
    Directory.Create(dirpath);
    

提交回复
热议问题