May-29-2022, 07:38 AM
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