Search the Community
Showing results for tags 'file deletion'.
-
Been a while since I contributed some code in this section of the forum ... mostly because I'm still using older versions of AutoIt. However, I recently started using the following function, as I thought it was a good idea. I'm sharing it for the same reasons, especially in light of the fact, that people do make mistakes, and sometimes incredibly stupid ones. That's the ever present nature of humanity I guess. This is only a pretty basic function, taken straight from my latest program, which others may need to modify, as it is mostly centered on folders. If I was really serious about this, and qualified to make a UDF, then I would add a couple more arguments. [1] second would be provision of a list of other files/folders to protect. Maybe as a text file, with one path per line. [2] third would be an exception to an item currently protected, thus giving that power at need. $res = UnsafeToDeleteChecklist($destfld) If $res = 1 Then DirRemove($destfld, 1) Func UnsafeToDeleteChecklist($pth) ; Function prevents deletion of file or folder based on path, if an important system one. If $pth = @HomeDrive Or $pth = "C:\" Or StringInStr($pth, @WindowsDir) > 0 Or $pth = @ProgramFilesDir _ Or $pth = @AppDataCommonDir Or $pth = @DesktopCommonDir Or $pth = @DocumentsCommonDir _ Or $pth = @FavoritesCommonDir Or $pth = @ProgramsCommonDir Or $pth = @StartMenuCommonDir _ Or $pth = @StartupCommonDir Or $pth = @AppDataDir Or $pth = @CommonFilesDir Or $pth = @DesktopDir _ Or $pth = @FavoritesDir Or $pth = @MyDocumentsDir Or $pth = @ProgramsDir Or $pth = @StartMenuDir _ Or $pth = @StartupDir Or $pth = @UserProfileDir Or (StringLen($pth) = 3 And StringMid($pth, 2, 1) = ":") Then Return 0 Else Return 1 EndIf EndFunc ;=> UnsafeToDeleteChecklist Supposedly, if I remember rightly, Windows protect some files and locations, and has done so since about Win XP, but people change settings, and have more expansive requirements, hence my function. Plus, I'm not willing to test how protected Windows makes things. Be interesting to know, whether others have thought the same or done the same or have some good stories to tell about accidental deletions, especially with major consequences. We probably shouldn't discuss that here though, so I will now start a Chat topic, and link back to this topic.
-
- file deletion
- folder deletion
-
(and 2 more)
Tagged with: