Irfanview bucket is written in Visual Basic Script (VBS). Reference material at http://msdn.microsoft.com/en-us/library/d1wf56tt%28VS.85%29.aspx The Script is run by the Windows Script Host (WSH). Reference material at http://msdn.microsoft.com/en-us/library/f51wc7hz%28v=VS.85%29.aspx The purpose of Irfanview bucket is to make it easier to run Irfanview from a USB stick as a portable application using drag and drop methods. The script now starts with a comment stating the script name and version number. The version described here is v1.7 The Script is divided into sections. SETUP MAIN PROGRAM FUNCTIONS and SUBROUTINES n SETUP Creates two essential objects (i) A File Scripting Object (named objFSO in this script). The FSO object gives access to information about all drives, folders or files on the computer and allows those items to be saved, deleted, moved or copied. These items can be brought together and handled as collections which can be useful too. The FSO object also allows text file objects to be created so that they can be read, written to or amended. (ii) A shell object (named objShell in this script). The shell object enables other applications to be launched. The shell object can also provide useful System information such as the current location of the user Desktop or Appdata folder. Setup also sets initial values for various text strings. strImage and strTextFiles specify the file extensions that will be accepted for individual images and text lists respectively. The format is compatible with the custom file list found in the File associations dialog. They are used as filters in conjunction with the "IsWanted" function to prevent unwanted file types being accepted that might cause errors to be flagged. They can be edited to allow other image or list types to be opened. Be aware that Irfanview does not apply any filtering internally when it processes a text list. The above filters when applied by the "IsWanted" function are the only filtering applied when the script is used. strVBS, strDesktop, strTempfile, strShortcut and strApp hold path and file names identifying respectively the VBS script (Irfanview bucket.vbs),the user desktop on the host computer, the "Bucket list" file that holds the list of image files dropped onto the shortcut (Bucket list.txt), the script file shortcut itself on the user desktop (Irfanview bucket.lnk) and the Irfanview program file (i_view32.exe). The "Relocate" function is applied to strApp before use in case the drive letter or location on that drive has moved. The path of the script file is used as a guide for where to look for it. If strApp can still not be found a warning message is displayed and the script is terminated. (Bug corrected in v1.7). MAIN PROGRAM Unless there is already a shortcut to Irfanview bucket on the user desktop of the host computer, then one is created by calling the subroutine "make_link". Quote marks are added to strApp to ensure that it is not split at a space character should one exist in the path name. The ASCII form, chr(34), is used since quote marks can be misinterpreted by VBS. A Text File Object (f1) is opened to hold new images added to the Bucket List. Previous contents of this list are retained if the file already existed. WScriptArguments is an object that the Windows script host (WScript.exe) has created to hold all the file names that are dropped onto the Shortcut. They are held as "Arguments". The script now cycles through the Arguments using a For..Next loop. Each argument is expected to hold the name of a folder, a text file or some other file type. Whatever the source, every file name that is extracted is checked using the "IsWanted" function and if the extension, which indicates the file type, is included in strFilter the file is accepted. If the argument holds the name of a folder, objFSO is used to collect the files contained in it. A For..Next is then used to build the files into a list. If the argument is included in strText file it is accepted as a text file containing a list of images. A Text file object (fList) is opened for reading the list of images that it contains. Apart from the special case when the Bucket list itself has been dropped onto the shortcut, each line of text in the file that was dropped is examined using a Do..Loop to see if the file name currently exists on the path specified. If not it may be that the text file has been moved either from a different location on the current drive or from a different drive. The "Relocate" function is applied using the path of the list itself as a guide. This will generate a number of other possible paths and these will also be examined to see if the file name exists there. If the file name does exist on any of these paths, that path and name is added to the Bucket list. If no valid path is found for the image, the original file path and name are restored allowing the user to apply a different guide file later (new in v1.6). If the bucket list itself was dropped onto the shortcut it is assumed that the user just wants to reload that list, usually because the Irfanview File menu has been used meanwhile to open other images in the window. In this special case no new data is added to the existing Bucket list, but its size is increased by adding a blank line so that the file is not deleted again as soon as it has been reloaded (new in v1.6). If the argument is any other file type then this is checked directly using strImage and the "IsWanted" function and, if validated, added to the Bucket list. Note that text files extracted from lists or folders by the script are never treated as file lists but may still be added singly to the Bucket list if they are also a valid image type (e.g. .txt). When all arguments have been processed, the size of the Bucket list is saved for luse later. Irfanview is then run with a "/Killmesoftly" option. This closes any previous Irfanview window that is displaying an earlier list. Irfanview is then launched again with the "/filelist=" option. The newly created Bucket list is loaded and the first file in that list displayed. The script file now halts waiting for the window that was just opened to close again. The user may use this interval to drop some more files on the icon to extend the list or may be viewing the images that are already listed. If more image files are dropped on to the icon then another instance of the script starts up and, after the list has been extended, the "/killmesoftly" process will close the old window and release the halted program. If before that the user finishes viewing the images and closes the window manually, that will also release the halted file. When it resumes the script checks to see if the bucket file exists and if it does examines whether its size has changed while it was halted. If the file size has not changed it indicates that the window was closed by the user who has now finished using that list, so it is deleted. In the case where the last file size was zero then an empty Irfanview window has been opened and then closed again by the user, or an error has occurred when a user has tried to load files that contain no valid images. In either case it is taken to be a sign that the user may want to finish the session and clear away anything that has been added to the desktop by the script, including the shortcut itself. This option is offered by running the "Clear_desk" function. The user also has the alternative to keep the shortcut should they want to continue the session. On returning from the function the old script continues to its close. The script performs a clean close down by setting the objects that have been created to "Nothing", so releasing the memory they were using, and then terminates using the "WScript.Quit" function. FUNCTION IsWanted This function checks if the file type is contained in strFilter. If so "True" is returned, if not "False". FUNCTION Relocate This is a special function that attempts to repair broken paths to files. This happens often to files in lists on a memory stick. Most common is that the drive letter is incorrect because the computer that the stick is now plugged into has assigned a different drive letter to that assigned by the computer where the lists were prepared. Sometimes too whole nests of folders have been moved on to the stick from another computer along with lists of where they were originally. There a whole section of the start of the path may now be incorrect. Relocate works by using a guide file where the path name is known to be correct because it has been dragged from somewhere on the stick and dropped onto Irfanview bucket. Usually that is the text file which contains the file list. If an intermediate folder name within its path matches one in the path of the image being sought then the front section of the guide file path can be spliced to the tail of the image file path to effect a repair. The "objFSO.FileExists" method is used to check all the possible links generated until a valid image file is identified. If none is found the original path is returned with the image name. SUBROUTINE Make_link Creates a shortcut to the script file. This subroutine is based on an example in http://msdn.microsoft.com/en-us/library/aew9yb99%28v=vs.84%29.aspx The initial size of the Bucket list file is set to -1 so that the Clear_desk routine is not called until the new shortcut has been used. Subroutine Clear_desk A message dialog box is generated to offer an option to automatically close down the session if the user has finished with the program. Pressing the "OK" button will clear from the desktop the shortcut icon and anything else left behind by the program. Pressing the "CANCEL" button allows the user to continue using the program if they do not want to end the session.