1

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])):
        webbrowser.open(os.path.join(r,image))
  return

closed as off-topic by artwork21, Devdatta Tengshe, Stephen Lead, PolyGeo, BradHards Jul 9 '14 at 10:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development are off-topic here unless they relate directly to Geographical Information Systems, but they can be asked on Stack Overflow." – artwork21, Stephen Lead, PolyGeo, BradHards
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 '14 at 1:25
  • Which place does it fail? what error does it give? – Devdatta Tengshe Jul 9 '14 at 3:22
0

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))
    else:
        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.