(imported topic written by RichB91)
I have a nagging feeling that the code we’re using is just not being efficient. In several places, I have code that does two or more of the same actions just with different folder names (or *.exe names, or processes, or Reg entries, or…)
Using the example below that tests for the existence of three different directories and creates them if they aren’t present, it is being done with three separate If/Then constructs.
Is there a way, possibly using RegEx or some kind of
It Of List of Folders
, to perform these three steps with fewer lines of code?
Again, this particualr example isn’t really a serious problem. It’s just three short If/then statements. But sometimes there are five to ten items in the list that need the same action and I’d really rather not duplicate the code so often. It makes future edits highly problematic.
// Do not continue unless the OS is Windows
Continue If {name of operating system as string as lowercase contains “win”}
// Set Task parameters
Parameter “DirScripts” = “C:\companyname_Tools\BigFix\Scripts”
Parameter “DirArchives” = “C:\companyname_Tools\BigFix\Archives”
Parameter “DirLogs” = “C:\companyname_Tools\BigFix\Logs”
// If companyname proprietary BigFix Script directory doesn’t exist, create directory
If {not exists folder (parameter “DirScripts”)}
waithidden cmd.exe /C mkdir “{parameter “DirScripts”}”
endif
// If companyname proprietary BigFix Archive directory doesn’t exist, create directory
If {not exists folder (parameter “DirArchives”)}
waithidden cmd.exe /C mkdir “{parameter “DirArchives”}”
endif
// If companyname proprietary BigFix Log directory doesn’t exist, create directory
If {not exists folder (parameter “DirLogs”)}
waithidden cmd.exe /C mkdir “{parameter “DirLogs”}”
endif