1

I have photos grouped by albums, with a different folder for each album. I would like to open a folder/album randomly to add variety when viewing photo albums. I already know of an image viewer than can shuffle the viewing order of images; I'm looking for a way to randomly open a folder within a directory to complement it.

The OS I am using is Windows 7.

Oliver Salzburg
  • 87,539
  • 63
  • 263
  • 308
  • Open the directory in explorer? – invert Nov 12 '10 at 11:35
  • 1
    I've written a random music album chooser for this very reason. – ChrisF Nov 12 '10 at 13:04
  • @wez Yes, open a random folder/directory and show it using Windows Explorer. Or if there's an image viewer program that can open it within its own directory viewer, that would be fine too, although I prefer that it be opened with Explorer so I can choose which program to use to open the image files. – galacticninja Nov 13 '10 at 10:19

1 Answers1

1

This Python script will open a random directory, it takes the working directory to randomize as an argument. You can setup a shortcut to call this as well.

#!/usr/bin/env python
#open-random.py
import os
import sys
import random
import subprocess
if __name__ == "__main__":
    if len(sys.argv) == 2:
        dirname = sys.argv[1]
        li = [f for f in os.listdir(dirname) if os.path.isdir(os.path.join(dirname, f))]
        random_dir = li[random.randint(0, len(li)) - 2]
        random_dir = os.path.join(dirname, random_dir)
        print('opening %s' % (random_dir))
        subprocess.call(['explorer.exe', random_dir])
    else:
        print('Usage: python open-random.py base-directory')

Usage: python open-random.py "c:\photos"

invert
  • 5,006
  • Sir, could you point me to the installation instructions and software I need to install to be able to use this Python script? (I've never used one before.) – galacticninja Nov 13 '10 at 10:23
  • If you go to www.python.org you can find great install instructions and the setup download too. Also look at http://www.irfanview.com you can view images randomly and open an image with external editor directly, and has a thumbnail browser. Might be what you need. – invert Nov 16 '10 at 06:53