How do I open a random folder within a specified directory?

0

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.

galacticninja

Posted 2010-11-12T11:10:16.223

Reputation: 5 348

Open the directory in explorer? – invert – 2010-11-12T11:35:39.187

I've written a random music album chooser for this very reason. – ChrisF – 2010-11-12T13:04:32.397

@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 – 2010-11-13T10:19:26.193

Answers

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

Posted 2010-11-12T11:10:16.223

Reputation: 4 918

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 – 2010-11-13T10:23:51.260

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 – 2010-11-16T06:53:23.657