You can also place a shortcut to the script in your Send To folder, which
eliminates the .vbs filename extension that would otherwise appear in
Explorer??™s Send To menu.
In either case, when Windows executes the script, the names of the input
file(s) are accessible as command-line parameters, one for each filename.
The following example script displays the names of all the files and folders
drag-dropped on the script icon:
Report = ""
Set Arguments = WScript.Arguments
For i = 1 to Arguments.Count
Report = Report + Arguments(i - 1) + vbCrLf
Next
Msgbox Report
The script starts off by clearing the Report variable, and then borrows some
code from the CommandLine function listed earlier* to initialize the Arguments
object and determine the number of dropped files. Next, a For...Next
* It??™s actually possible to use the CommandLine function here instead, but doing so would make the
script more cumbersome. And exactly who are you going to impress with a cumbersome script?
536 | Chapter 9: Scripting and Automation
structure runs through the arguments, adding each one to the Report variable,
followed by a linefeed (using vbCrLf, a handy built-in constant containing
carriage-return and linefeed characters). Note that the Arguments array is
zero-based (the first item is Arguments(0), the second is Arguments(1), and so
on), so the (i - 1) part is needed to compensate. Lastly, a Msgbox command
is used to display the list of dropped files.
Pages:
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745