Share via


WSH Drag and Drop Support

You can drag files onto a WSH script. The file names are translated into arguments on the command line. These file names can be displayed in a list, which you can use to manipulate files with any scripting object.

Procedures

To display a script's argument list

  1. Create a file and give it a name with a script extension (for example, DragDrop.vbs).

  2. Add code to the script file, for example:

    var objArgs = WScript.Arguments;
    for (var i = 0; i < objArgs.Count(); i++)
    {
        WScript.Echo(objArgs(i));
    }
    
    Set objArgs = WScript.Arguments
    For I = 0 to objArgs.Count - 1
       WScript.Echo objArgs(I)
    Next
    
  3. Save the file to your hard disk.

  4. Drag and drop any file or files onto your saved file. In the example, the file names are echoed back to the screen.

The number of files you can drag onto a script is limited by your system's maximum command-line length. If the total number of characters in all file names being dragged exceeds this limit, the drag and drop operation fails.

Change History

Date

History

Reason

September 2009

Added JScript example.

Customer feedback.