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

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

   1 from   wxPython.wx     import *
   2 from win32api import ShellExecute
   3 from random import choice
   4 
   5 if wxTheClipboard.Open():
   6     data = wxFileDataObject()
   7     wxTheClipboard.GetData(data)
   8     wxTheClipboard.Close()
   9 
  10     playList = data.GetFilenames()
  11     if playList:
  12         count = 0
  13         while 1 :
  14             selection = choice(playList)
  15             ShellExecute(0, None, selection, None, 'c:\\', 1)
  16             count += 1
  17             if count > len(playList): break
  18     else:
  19         print ".... List seems to be empty"
  20 else:
  21     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

ProcessingFilenamesSentToClipboardFromWindowsExplorer (last edited 2012-05-25 18:58:57 by 216)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.