Skip to content

Instantly share code, notes, and snippets.

@vvps
Last active August 29, 2015 14:11
Show Gist options
  • Save vvps/182b1544f07379835e5d to your computer and use it in GitHub Desktop.
Save vvps/182b1544f07379835e5d to your computer and use it in GitHub Desktop.
A Python script to open file(s) in a root folder with regex like input
import os
import sys
import fnmatch
from PIL import Image
dirPath = r'I:\A_folder_with_photos_and_subfolders'
if len(sys.argv) > 1:
searchParam = sys.argv[1]
regExpParam = '*' + searchParam + '*.*'
else:
print('Enter a search parameter')
exit
if os.path.exists(dirPath):
os.chdir(dirPath)
else:
print('Directory does not exist - Connect to server')
def showImage(rootName, fileName):
print (os.path.join(rootName,fileName))
os.startfile(os.path.join(rootName,fileName))
return
for root, subDir, files in os.walk('.'):
for file in files:
if fnmatch.fnmatch(file, regExpParam):
showImage(root, file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment