Python Forum
pdf2image, poppler and paths
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pdf2image, poppler and paths
#16
Warning: This is a hack
There's probably a better way to do this, but I've used it for years and it suits my purposes:
Also, probably won't work on MS Windows since I use symbolic links. Not sure, I'm pretty much
A Linux only person.

import os
from pathlib import Path
 
 
class MyPaths:
    def __init__(self, depth=0):
        os.chdir(os.path.abspath(os.path.dirname(__file__)))

        dir_depth = abs(depth)

        HomePath = Path(".")

        while dir_depth:
            HomePath = HomePath / ".."
            dir_depth -= 1
 
        rootpath = HomePath / ".."
 
        self.datapath = rootpath / "data"
        self.datapath.mkdir(exist_ok=True)
 
        self.csvpath = self.datapath / "csv"
        self.csvpath.mkdir(exist_ok=True)
 
        self.docpath = rootpath / "docs"
        self.docpath.mkdir(exist_ok=True)
 
        self.jsonpath = self.datapath / "json"
        self.jsonpath.mkdir(exist_ok=True)
 
        self.htmlpath = self.datapath / "html"
        self.htmlpath.mkdir(exist_ok=True)
 
        self.pdfpath = self.datapath / 'PDF'
        self.pdfpath.mkdir(exist_ok=True)
 
        self.tmppath = self.datapath / "tmp"
        self.tmppath.mkdir(exist_ok=True)
 
 
if __name__ == "__main__":
    MyPaths(depth=0)
now if you have a source directory like:

├── data
│ ├── csv
│ ├── PDF
│ └── tmp
├── docs
├── src
│ ├── ProvingGround
│ └──
│ ├─ MyProg.py
│ └── Create symbolic link to MyPaths.py here
└── venv
└── ...

then to use MyPaths in MyProg.py, instanceiate like mpath = MyPaths(depth=1)
if you have more directories below Proving Ground, increase size of depth accordingly

EDIT:
Note You most likely figured this out, depth is optional, 0 is assumed if not supplied.
jehoshua likes this post
Reply


Messages In This Thread
pdf2image, poppler and paths - by jehoshua - Jun-11-2022, 02:21 AM
RE: pdf2image, poppler and paths - by Larz60+ - Jun-11-2022, 02:38 AM
RE: pdf2image, poppler and paths - by jehoshua - Jun-11-2022, 04:20 AM
RE: pdf2image, poppler and paths - by DPaul - Jun-11-2022, 05:56 AM
RE: pdf2image, poppler and paths - by jehoshua - Jun-11-2022, 07:08 AM
RE: pdf2image, poppler and paths - by Larz60+ - Jun-11-2022, 09:10 AM
RE: pdf2image, poppler and paths - by jehoshua - Jun-11-2022, 11:30 PM
RE: pdf2image, poppler and paths - by snippsat - Jun-11-2022, 10:34 AM
RE: pdf2image, poppler and paths - by jehoshua - Jun-11-2022, 11:40 PM
RE: pdf2image, poppler and paths - by Larz60+ - Jun-12-2022, 01:56 PM
RE: pdf2image, poppler and paths - by jehoshua - Jun-13-2022, 03:23 AM
RE: pdf2image, poppler and paths - by Larz60+ - Jun-13-2022, 07:17 AM
RE: pdf2image, poppler and paths - by jehoshua - Jun-13-2022, 08:16 AM
RE: pdf2image, poppler and paths - by Larz60+ - Jun-13-2022, 11:04 AM
RE: pdf2image, poppler and paths - by jehoshua - Jun-13-2022, 09:52 PM
RE: pdf2image, poppler and paths - by Larz60+ - Jun-13-2022, 10:42 PM
RE: pdf2image, poppler and paths - by jehoshua - Jun-13-2022, 10:44 PM
RE: pdf2image, poppler and paths - by snippsat - Jun-14-2022, 12:46 AM
RE: pdf2image, poppler and paths - by jehoshua - Jun-14-2022, 06:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Windows paths issue otalado 3 1,531 May-29-2022, 09:11 AM
Last Post: snippsat
  automatically get absolute paths oclmedyb 1 2,160 Mar-11-2021, 04:31 PM
Last Post: deanhystad
  chkFile with absolute paths JarredAwesome 7 3,067 Sep-21-2020, 03:51 AM
Last Post: bowlofred
  Paths millpond 12 5,356 Jul-30-2020, 01:16 PM
Last Post: snippsat
  Problems with windows paths delphinis 6 5,382 Jul-21-2020, 06:11 PM
Last Post: Gribouillis
  'No module named pdf2image' ironfelix717 13 22,587 Jul-24-2019, 11:54 AM
Last Post: snippsat
  Shortest paths to win snake and ladder sandaab 5 4,338 Jun-30-2019, 03:20 PM
Last Post: sandaab
  How to handle paths with spaces in the name? zBernie 1 6,816 Nov-22-2018, 04:04 AM
Last Post: ichabod801
  Question: Paths and writing to a file mwmaw 6 6,626 Dec-20-2016, 03:44 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020