Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MacOS can't make it
#2
using pathlib:
from pathlib import Path
from BadgePaths import BadgePaths

bpath = BadgePaths()
path = Path(bpath.htmlpathNh)

for p in path.rglob("*"):
     print(p.name)
BadgePaths.py looks like:
import os
from pathlib import Path


class BadgePaths:
    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.htmlpath = self.datapath / "html"
        self.htmlpath.mkdir(exist_ok=True)

        self.htmlpathNh = self.htmlpath / "NewHampshire"
        self.htmlpathNh.mkdir(exist_ok=True)

        self.samplesNh = self.htmlpathNh / 'Samples'
        self.samplesNh.mkdir(exist_ok=True)
        
        self.imagepath = self.datapath / 'images'
        self.imagepath.mkdir(exist_ok=True)
        
        self.logpath = self.datapath / 'logs'
        self.logpath.mkdir(exist_ok=True)
        
        self.prettypath = self.datapath / "pretty"
        self.prettypath.mkdir(exist_ok=True)

        self.srcpath = rootpath / 'src'
        self.srcpath.mkdir(exist_ok=True)

        self.textpath = self.datapath / 'text'
        self.textpath.mkdir(exist_ok=True)

        self.tmppath = self.datapath / "tmp"
        self.tmppath.mkdir(exist_ok=True)


if __name__ == "__main__":
    BadgePaths()
partial results:
Output:
NhBusinessListingsPage9993.html NhBusinessListingsPage9994.html NhBusinessListingsPage9995.html NhBusinessListingsPage9996.html NhBusinessListingsPage9997.html NhBusinessListingsPage9998.html NhBusinessListingsPage9999.html Samples
Reply


Messages In This Thread
MacOS can't make it - by Archi - May-29-2022, 01:09 AM
RE: MacOS can't make it - by Larz60+ - May-29-2022, 07:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python installation for old MacOS Yonix 1 516 Sep-21-2023, 03:32 PM
Last Post: menator01
  Why is IDLE not opening on a MacOS Montery 12.6 and using Python 3.10.7? Merlin385 7 1,766 Oct-08-2022, 08:36 PM
Last Post: Merlin385
  Text widget -macOS apffal 1 1,784 Sep-23-2021, 10:12 PM
Last Post: apffal
  Installing Python3 on MacOS using brew zazas321 5 5,296 May-28-2021, 06:19 AM
Last Post: perfringo
  Building from source on MacOS: installing certificates ardim 1 2,003 Feb-09-2020, 10:16 PM
Last Post: ardim
  can't open excel with my macos dcc 0 2,398 Oct-30-2019, 04:18 AM
Last Post: dcc
  pymysql on macos seirra tony1812 5 4,603 Sep-17-2017, 03:24 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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