Last active
August 29, 2015 14:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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