mr-es335 Posted November 19, 2023 Posted November 19, 2023 Good day, In the following two examples, which of the two would be preferred and why? Any clarification would be greatly appreciated! ; ----------------------------------------------- ; Example #A ; ----------------------------------------------- #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Uninstall_App() Func Uninstall_App() Local $src_folder = "C:\App" ; ----------------- If FileExists($src_folder) Then If DirRemove($src_folder, 1) = False Then Shutdown(0) ; Direct use of command ; ----------------- MsgBox(4096, "Result", "Folder Deleted Successfully") Else MsgBox(4096, "Result", "Folder does not exist") EndIf EndFunc ;==>Uninstall_App ; ----------------------------------------------- ; ----------------------------------------------- ; Example #B ; ----------------------------------------------- #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Uninstall_App() unc Uninstall_App() Local $src_folder = "C:\App" ; ----------------- If FileExists($src_folder) Then Local $bDirRemove = DirRemove($src_folder, 1) ; Use of a variable If $bDirRemove = False Then Shutdown(0) ; ----------------- MsgBox(4096, "Result", "Folder Deleted Successfully") Else MsgBox(4096, "Result", "Folder does not exist") EndIf EndFunc ;==>Uninstall_App ; ----------------------------------------------- So, my questions then are: Q1: "A or B?" R1: Q2: "Why?" R2: Thank you all for your time....appreciated! mr-es335 Sentinel Music Studios
paw Posted November 19, 2023 Posted November 19, 2023 (edited) If Not DirRemove($src_folder, 1) Then Shutdown(0) Because DirRemove returns either 1 or 0 just use logical "Not", easy to read and understand too. Dont write " = False" or " = True", the opposite of the above would just be If DirRemove($src_folder, 1) Then ConsoleWrite("Success!") Only capture the result in a variable if you need it Edited November 19, 2023 by paw
mr-es335 Posted November 19, 2023 Author Posted November 19, 2023 paw, Thanks for the response! I would assume then that with regards to Q1, that "A" would be acceptable..but with your suggestion of the use of "Not"? Could you please provide a response to Q2? mr-es335 Sentinel Music Studios
paw Posted November 19, 2023 Posted November 19, 2023 12 minutes ago, paw said: Only capture the result in a variable if you need it my edit if you missed it, an example would be if you want to log the outcome or use it further down in the code
argumentum Posted November 19, 2023 Posted November 19, 2023 https://www.autoitscript.com/autoit3/docs/functions/DirRemove.htm it returns 1 or 0, not True False Other than that I don't understand your code or it's use. Nor like your disregard in reading the help file. I shouldn't be responding. Anyway, is 1/0 not true/false Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now