c# - How to delete AppData\Local\Geckofx\ when closing my browser? -
i'm working on gecko based web browser , i'd delete appdata\local\geckofx\ on exit.
i'm using code:
protected override void onformclosing(formclosingeventargs e) { try { var dir = new directoryinfo(@"c:\users\admin\appdata\local\geckofx\"); dir.attributes = dir.attributes & ~fileattributes.readonly; dir.delete(true); } catch { } }
of course delete if user has name "admin". there way make work usernames? plus i've noticed won't delete in folder, there way force delete or isn't recommended?
to delete files , folders in folder ; use code :
foreach (fileinfo file in thedirectory.getfiles()) { file.delete(); } foreach (directoryinfo dir in thedirectory.getdirectories()) { dir.delete(true); }
on stackoverflow thread found code delete read-only files :
private static void deletefilesysteminfo(filesysteminfo fsi) { fsi.attributes = fileattributes.normal; var di = fsi directoryinfo; if (di != null) { foreach (var dirinfo in di.getfilesysteminfos()) { deletefilesysteminfo(dirinfo); } } fsi.delete(); }
Comments
Post a Comment