I have the below python script which recursively walks through a directory and finds, then opens the associated parcel pdf file. How would I modify this to not be recursive but to just look in the directory of "\corp.qr.com.au\app\QRGIS\QRData\Leases\Lease_Plans\Active" I can't seem to get it to work. Thanks

import webbrowser, os
def OpenLink([File_Name]):
  for r,d,f in os.walk(r"\\corp.qr.com.au\app\QRGIS\QRData\Leases\Lease_Plans\"):
    for image in f:
      if image.startswith(str([File_Name])):
  • Welcome to GIS SE, although you are using Arc to run a python script your question does not relate to the scope of this forum. Please edit it to relate.
    – artwork21
    Jul 9, 2014 at 1:25
  • Which place does it fail? what error does it give? Jul 9, 2014 at 3:22

1 Answer 1


Here is your code, this will serve your requirements.

import webbrowser
import os

def open_file(directory, filenames):
    """ open the files in new window """
    if os.path.isdir(directory):
        for dir_file in os.listdir(directory):
            if dir_file in filenames:
                webbrowser.open_new(os.path.join(directory, dir_file))
        print "Given directory does not exist."

# Inputs directory path and files list
dir_path = r'Your directory path'
# file names are case sensitive
files = ["File_1.pdf", "File_2.pdf","Text_file.txt"]
open_file(dir_path, files)

Not the answer you're looking for? Browse other questions tagged or ask your own question.