omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to check presence of a file relative to current document

    Editorial
    2
    4
    1976
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MartinPacker
      MartinPacker last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • peterh86
        peterh86 last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • MartinPacker
          MartinPacker last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • MartinPacker
            MartinPacker last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors