Create Check Boxes Dynamically Based On File List
Moderators: Dorian (MJT support), JRL
Create Check Boxes Dynamically Based On File List
I maintain several databases and want to create a distribution tool which allows me to send out one or more installation files to my customers. I would like the tool to be dynamic so that I don't have to adjust whenever a database is created or retired. We use the same naming convention for each database/installation file which looks like this.
Application Name is the only variable we need to worry about.
\\NetworkLocation\ApplicationName\Production\ApplicationNameInstall.exe
What I'd like to do is have a checkbox generated for each folder in ApplicationName. The user could then select the applications they need and the tool would generate an email with all of the selected files attached.
This doesn't seem unreasonable to me but I have never done anything in this vein so I'm not sure how to go about it.
Application Name is the only variable we need to worry about.
\\NetworkLocation\ApplicationName\Production\ApplicationNameInstall.exe
What I'd like to do is have a checkbox generated for each folder in ApplicationName. The user could then select the applications they need and the tool would generate an email with all of the selected files attached.
This doesn't seem unreasonable to me but I have never done anything in this vein so I'm not sure how to go about it.
Thanks,
Josh
Josh
creating dynamic dialog
This should give you some ideas. It dynamically builds a script with a dialog. It creates a checkbox for every folder it finds in the GetFileList> command. I'm using Macro Scheduler version 10.1.21 for this example.
[code]
IfFileExists>%TEMP_DIR%\Temp1.scp
DeleteFile>%TEMP_DIR%\Temp1.scp
Endif
WriteLn>%TEMP_DIR%\Temp1.scp,r,Dialog>Dialog1
WriteLn>%TEMP_DIR%\Temp1.scp,r, Caption=This is My Dialog
WriteLn>%TEMP_DIR%\Temp1.scp,r, Width=500
WriteLn>%TEMP_DIR%\Temp1.scp,r, Height=603
WriteLn>%TEMP_DIR%\Temp1.scp,r, Top=132
WriteLn>%TEMP_DIR%\Temp1.scp,r, Left=40
Let>GFL_TYPE=1
//GetFileList>\\NetworkLocation\ApplicationName\*.*,strFileList,;
GetFileList>s:\xfer\alan\*.*,strFileList,;
Separate>strFileList,;,folders
If>folders_count=0,End
Let>x=24
Let>y=30
Let>k=0
Repeat>k
Let>k=k+1
Let>y=y+20
Let>caption=folders_%k%
WriteLn>%TEMP_DIR%\Temp1.scp,r, CheckBox=msCheckBox%k%,%caption%,%x%,%y%,200,False
Until>k,folders_count
WriteLn>%TEMP_DIR%\Temp1.scp,r, Button=Bundle Install,20,10,89,33,3
WriteLn>%TEMP_DIR%\Temp1.scp,r, Button=Exit,120,10,100,30,2
WriteLn>%TEMP_DIR%\Temp1.scp,r,EndDialog>Dialog1
WriteLn>%TEMP_DIR%\Temp1.scp,r,Label>MainLoop
WriteLn>%TEMP_DIR%\Temp1.scp,r, Show>Dialog1,result
WriteLn>%TEMP_DIR%\Temp1.scp,r, If>result=2,End
WriteLn>%TEMP_DIR%\Temp1.scp,r, If>result=3,Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r,Goto>MainLoop
WriteLn>%TEMP_DIR%\Temp1.scp,r,SRT>Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r, MessageModal>Install Ready
WriteLn>%TEMP_DIR%\Temp1.scp,r, //
WriteLn>%TEMP_DIR%\Temp1.scp,r,WriteLn>%TEMP_DIR%\Temp1.scp,r, // your code here
WriteLn>%TEMP_DIR%\Temp1.scp,r, //
WriteLn>%TEMP_DIR%\Temp1.scp,r,END>Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r,Label>End
//Now execute the script I just built
ExecuteFile>%TEMP_DIR%\temp1.scp
[/code]
[code]
IfFileExists>%TEMP_DIR%\Temp1.scp
DeleteFile>%TEMP_DIR%\Temp1.scp
Endif
WriteLn>%TEMP_DIR%\Temp1.scp,r,Dialog>Dialog1
WriteLn>%TEMP_DIR%\Temp1.scp,r, Caption=This is My Dialog
WriteLn>%TEMP_DIR%\Temp1.scp,r, Width=500
WriteLn>%TEMP_DIR%\Temp1.scp,r, Height=603
WriteLn>%TEMP_DIR%\Temp1.scp,r, Top=132
WriteLn>%TEMP_DIR%\Temp1.scp,r, Left=40
Let>GFL_TYPE=1
//GetFileList>\\NetworkLocation\ApplicationName\*.*,strFileList,;
GetFileList>s:\xfer\alan\*.*,strFileList,;
Separate>strFileList,;,folders
If>folders_count=0,End
Let>x=24
Let>y=30
Let>k=0
Repeat>k
Let>k=k+1
Let>y=y+20
Let>caption=folders_%k%
WriteLn>%TEMP_DIR%\Temp1.scp,r, CheckBox=msCheckBox%k%,%caption%,%x%,%y%,200,False
Until>k,folders_count
WriteLn>%TEMP_DIR%\Temp1.scp,r, Button=Bundle Install,20,10,89,33,3
WriteLn>%TEMP_DIR%\Temp1.scp,r, Button=Exit,120,10,100,30,2
WriteLn>%TEMP_DIR%\Temp1.scp,r,EndDialog>Dialog1
WriteLn>%TEMP_DIR%\Temp1.scp,r,Label>MainLoop
WriteLn>%TEMP_DIR%\Temp1.scp,r, Show>Dialog1,result
WriteLn>%TEMP_DIR%\Temp1.scp,r, If>result=2,End
WriteLn>%TEMP_DIR%\Temp1.scp,r, If>result=3,Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r,Goto>MainLoop
WriteLn>%TEMP_DIR%\Temp1.scp,r,SRT>Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r, MessageModal>Install Ready
WriteLn>%TEMP_DIR%\Temp1.scp,r, //
WriteLn>%TEMP_DIR%\Temp1.scp,r,WriteLn>%TEMP_DIR%\Temp1.scp,r, // your code here
WriteLn>%TEMP_DIR%\Temp1.scp,r, //
WriteLn>%TEMP_DIR%\Temp1.scp,r,END>Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r,Label>End
//Now execute the script I just built
ExecuteFile>%TEMP_DIR%\temp1.scp
[/code]
Update:
I am using the following to gather the list of folders and display them in a ListBox. Something along these lines will work, I just need a way to return the selected values and then cycle through them to fetch the appropriate attachments.
I am using the following to gather the list of folders and display them in a ListBox. Something along these lines will work, I just need a way to return the selected values and then cycle through them to fetch the appropriate attachments.
Code: Select all
Let>GFL_TYPE=1
GetFileList>\\rnodata01\scrub$\Live_Databases\*,FList,%CRLF%
Dialog>Dialog4
Caption=Dialog4
Width=445
Height=250
Top=104
Left=16
ListBox=msListBox1,6,11,419,97,%FList%,true
EndDialog>Dialog4
Show>Dialog4,result
Thanks,
Josh
Josh
Well, based upon the code you posted using the listbox, this should loop through the items selected.
[code]
Let>GFL_TYPE=1
//GetFileList>\\rnodata01\scrub$\Live_Databases\*,FList,%CRLF%
GetFileList>s:\xfer\alan\*.*,FList,%CRLF%
Dialog>Dialog4
Caption=Dialog4
Width=445
Height=250
Top=132
Left=40
ListBox=msListBox1,6,11,419,97,%FList%,true
Button=Build Selected,72,152,81,25,4
Button=Exit,288,152,81,25,3
EndDialog>Dialog4
Show>Dialog4,result
If>result=4
GoSub>Build
Endif
SRT>Build
Separate>Dialog4.msListBox1,%CRLF%,myitems
If>myitems_count>0
Let>mySelected=0
Repeat>mySelected
Add>mySelected,1
Let>myitem=myitems_%mySelected%
MessageModal>myitem
// Do what you what here
// more code...
//
Until>mySelected,myitems_count
Endif
END>Build
[/code]
[code]
Let>GFL_TYPE=1
//GetFileList>\\rnodata01\scrub$\Live_Databases\*,FList,%CRLF%
GetFileList>s:\xfer\alan\*.*,FList,%CRLF%
Dialog>Dialog4
Caption=Dialog4
Width=445
Height=250
Top=132
Left=40
ListBox=msListBox1,6,11,419,97,%FList%,true
Button=Build Selected,72,152,81,25,4
Button=Exit,288,152,81,25,3
EndDialog>Dialog4
Show>Dialog4,result
If>result=4
GoSub>Build
Endif
SRT>Build
Separate>Dialog4.msListBox1,%CRLF%,myitems
If>myitems_count>0
Let>mySelected=0
Repeat>mySelected
Add>mySelected,1
Let>myitem=myitems_%mySelected%
MessageModal>myitem
// Do what you what here
// more code...
//
Until>mySelected,myitems_count
Endif
END>Build
[/code]
Ok, rummaging through the ListBox is a bit more in line with my limited expertise. I got what you sent me working but I have one more step to complete. My file structure/naming convention throughout is \\NetworkLocation\ApplicationName\Production\ApplicationNameInstall.zip. I want to use the \\NetworkLocation\ApplicationName from the list box, add \Production\ and then search for any file with "install.zip" within the production folder. I then need them all in one string so I can attach all selected application installers to a single email.
You have been a huge help so far, thanks!
Josh
You have been a huge help so far, thanks!
Josh
Code: Select all
Let>GFL_TYPE=1
//GetFileList>\\rnodata01\scrub$\Live_Databases\*,FList,%CRLF%
GetFileList>c:\*.*,FList,%CRLF%
Dialog>Dialog4
Caption=Dialog4
Width=445
Height=250
Top=132
Left=40
ListBox=msListBox1,6,11,419,97,%FList%,true
Button=Build Selected,72,152,81,25,4
Button=Exit,288,152,81,25,3
EndDialog>Dialog4
Show>Dialog4,result
If>result=4
GoSub>Build
Endif
SRT>Build
Let>Attach_string=
Separate>Dialog4.msListBox1,%CRLF%,myitems
If>myitems_count>0
Let>mySelected=0
Repeat>mySelected
Add>mySelected,1
Let>myitem=myitems_%mySelected%
Let>full_path=%myitem%\Production\Install.zip
IfFileExists>full_path
Let>Attach_string=%Attach_string%%full_path%;
Endif
// Do what you want here
// more code...
//
Until>mySelected,myitems_count
Endif
MessageModal>Attach_string
END>Build
Not sure how one string is going to help.... but anyway my code sample builds one string named "Attach_string" with all the file names separated by a semicolon.I then need them all in one string so I can attach all selected application installers to a single email.
Is there something missing from this line?
The final product should look like this, assuming I selected ApplicationName1 and ApplicationName2 in my list box. So that when I call it in my generated email I have all of the attachments in one string. Does that make sense?
\\NetworkLocation\ApplicationName1\Production\ApplicationName1Install.zip;\\NetworkLocation\ApplicationName2\Production\ApplicationName2Install.zip
Thanks again for your generosity,
Josh
Code: Select all
Let>Attach_string=
\\NetworkLocation\ApplicationName1\Production\ApplicationName1Install.zip;\\NetworkLocation\ApplicationName2\Production\ApplicationName2Install.zip
Thanks again for your generosity,
Josh