Forum Archive

How to check presence of a file relative to current document

MartinPacker

I have a workflow, mostly written in Python, that checks things like missing footnote definitions and unused ones. I'd like to extend it a little further - as part of a "checking my blog post is ready for publishing" workflow.

The next step I want to take is to check all the graphics exist in my Dropbox hierarchy (whether they've been uploaded to the eventual blogging site or not).

The image URIs are of the form ../resource/test1.png

This is obviously meant to be relative to the text of the blog post - as it will be in the target blog website. (I don't feel the need at 35,000 feet to check if the graphic is indeed on the target blog website; Local Dropbox hierarchy is enough.)

Given this URI form is relative to the document and not to the Python current working directory how can I check the existence of such a URI?

peterh86

This workflow finds files in the same folder as the current document (in Dropbox).

http://editorial-app.appspot.com/workflow/6453713958862848/81eiZlBdpKA

It uses glob.glob to scan the folder; there is another Python command that scans sub folders too if you need that.

MartinPacker

Thanks for replying @peterh

So glob.glob is something I am unfamiliar with. Does it turn e.g. "../resource/blah" into a fully qualified path I can then check against?

MartinPacker

In the end I took a different approach:

1) Change working directory to the document directory.

2) Use os.path.isfile(URI) to check for file's existence - for each image reference in the source document.

3) Perhaps unnecessarily switch back to original workflow current working directory.