Note that there are some explanatory texts on larger screens.

plurals
  1. PODirectoy.Delete(path, true) -> IOException : the directory is not empty -> Different owners on Win7
    primarykey
    data
    text
    <p>On uninstalling, I get a IOException when trying to delete a directory. 'The directory is not empty'. I tried different methods, listed below, but nothing works. The files that are left behind (and cannot be deleted) have a different owner. Files that can be deleted have owner 'SYSTEM'. Files that throw an exception have owner 'Administrators(PC_Name\Administrators)' 'System' files have been written by the installshield installer (MSI), while the other files are written by my app, launched by installshield and elevated to administrator ...</p> <p>How can I force a delete of this folder / files?</p> <pre><code> //http://stackoverflow.com/questions/329355/cannot-delete-directory-with-directory-deletepath-true public static bool DeleteDirectory(string target_dir) { bool result = false; string[] files = Directory.GetFiles(target_dir); string[] dirs = Directory.GetDirectories(target_dir); foreach (string file in files) { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } foreach (string dir in dirs) { DeleteDirectory(dir); } Directory.Delete(target_dir, false); return result; } //http://stackoverflow.com/questions/611921/how-do-i-delete-a-directory-with-read-only-files-in-c private static void DeleteFileSystemInfo(FileSystemInfo fsi) { fsi.Attributes = FileAttributes.Normal; var di = fsi as DirectoryInfo; if (di != null) { foreach (var dirInfo in di.GetFileSystemInfos()) DeleteFileSystemInfo(dirInfo); } fsi.Delete(); } //http://stackoverflow.com/questions/611921/how-do-i-delete-a-directory-with-read-only-files-in-c public static void ForceDeleteDirectory(string path) { DirectoryInfo root; Stack&lt;DirectoryInfo&gt; fols; DirectoryInfo fol; fols = new Stack&lt;DirectoryInfo&gt;(); root = new DirectoryInfo(path); fols.Push(root); while (fols.Count &gt; 0) { fol = fols.Pop(); fol.Attributes = fol.Attributes &amp; ~(FileAttributes.Archive | FileAttributes.ReadOnly | FileAttributes.Hidden); foreach (DirectoryInfo d in fol.GetDirectories()) { fols.Push(d); } foreach (FileInfo f in fol.GetFiles()) { f.Attributes = f.Attributes &amp; ~(FileAttributes.Archive | FileAttributes.ReadOnly | FileAttributes.Hidden); f.Delete(); } } root.Delete(true); } </code></pre> <p>EDIT: Sorry, forgot this :</p> <p>On the folder that is giving problems, on installation, I'm giving the 'Users' account full control :</p> <pre><code> System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier( System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null); System.Security.Principal.NTAccount acct = sid.Translate(typeof(System.Security.Principal.NTAccount)) as System.Security.Principal.NTAccount; string usr = acct.ToString(); DirectoryInfo info = new DirectoryInfo(dir); DirectorySecurity ds = info.GetAccessControl(); ds.AddAccessRule(new FileSystemAccessRule(usr, FileSystemRights.FullControl, AccessControlType.Allow)); ds.AddAccessRule(new FileSystemAccessRule(usr, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); info.SetAccessControl(ds); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload