== Introduction == Reading and processing a series of filenames sent to the MSW clipboard from Windows Explorer. A useful little technique for applying the same processing to each of collection of files selected using Explorer. I use this script often to play a selection of MP3s. (This will explain why I've used random.choice.) == What Objects are Involved == * `wxPython.wx.wxTheClipboard`: for gaining access to the MSW clipboard * `wxPython.wx.wxFileDataObject`: as a container for a list of filenames from the clipboard * `win32api.ShellExecute`: for processing each of the filenames, with the app registered for a file of its type * `random.choice`: for making a random selection of a file from the list from the clipboard == Process Overview == 1. Launch Windows Explorer. 2. Select a collection of files to be processed by the script using Ctrl-Click. 3. Send the collection to the clipboard by right-clicking on one of the filenames and selecting 'Copy'. (Win2K: otherwise, YMMV.) 4. Launch the script that appears below. == Code == {{{ #!python from wxPython.wx import * from win32api import ShellExecute from random import choice if wxTheClipboard.Open(): data = wxFileDataObject() wxTheClipboard.GetData(data) wxTheClipboard.Close() playList = data.GetFilenames() if playList: count = 0 while 1 : selection = choice(playList) ShellExecute(0, None, selection, None, 'c:\\', 1) count += 1 if count > len(playList): break else: print ".... List seems to be empty" else: print "... Can't open clipboard" }}} === Comments === For the sake of simplicity, this script just plays the first k random selections from the list (k being the length of the list), which implies that not all of the selections will be played and that some selections will probably be played more than once. === Changes === kyle: changed part of the code bill: removed reference to my email address