Questions tagged [pathlib]

This tag is for questions about the Python built-in library pathlib, which offers classes representing filesystem paths with semantics appropriate for different operating systems.

This module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between Pure paths, which provide purely computational operations without I/O, and Concrete paths, which inherit from pure paths but also provide I/O operations.

Its strength lies in that it offers a powerful Object Oriented interface for working with paths, as opposed to the string-based interface offered by os.path.

This table offers a mapping between various os functions to their corresponding PurePath/Path equivalent.

635 questions
0
votes
2 answers

Python can't find my file because of a directory error

So I have a function that scrapes instagram data and stores the number of likes to a dictionary.I think I have the function set up right but when I try to run a print statement, I keep getting a error that it can't find the file I'm looking for to…
0
votes
0 answers

Reference Higher-Level Directories

To reference Higher-Level directories with os something like this '../../mydir' could work but I do not prefer os.path. Instead I prefer pathlib. This is which would work: from pathlib import Path path = Path('.').absolute().parent.parent /…
MaKaNu
  • 762
  • 8
  • 25
0
votes
0 answers

Glob fails recursion on networked location?

I'm attempting to grab the filepaths of a specific type of file (.EIA) recursively from a networked location, using pathlib for the first time. Attempting to search from top-level looks like this: >>> for path in…
0
votes
2 answers

Renaming files in a folder with pathlib and for loops

I've written the following renaming tool in Python. It was unintentionally moving all my files to a single directory until I added the os.chdir in my for loop, which then made it work better and keep each renamed file inside its correct folder. But…
Dude
  • 145
  • 1
  • 9
0
votes
3 answers

Control order of pathlib and string concatenation

I have a directory I want to save files to, saved as a Path object called dir. I want to autogenerate files names at that path using string concatenation. The only way I can get this to work in a single line is just through string concatenation: dir…
James Wright
  • 1,293
  • 2
  • 16
  • 32
0
votes
1 answer

Get Path to Subpackage in Python

I have a project that needs updating from python2 to python3. It currently uses pkg_resources, which has significant overhead (PyCon 2018 - Get Your Resources Faster with importlib.resources, by Barry Warsaw). It will be packaged into a zip file.…
adam.hendry
  • 4,458
  • 5
  • 24
  • 51
0
votes
0 answers

Use Pathlib with PyQt5

Since Pathlib is the clean way for Path operations for Python 3, I am wondering if it is possible to use a Path() straight forward with PyQt5. The biggest issue I have are the FileDialogs: mydefaultPath = Path('D:/mypath/') target =…
MaKaNu
  • 762
  • 8
  • 25
0
votes
1 answer

Pattern for extracting paths where filename starts with 0/ 1 using pathlib glob

I tried using normal python regex patterns in pathlib glob but it's not working. While reading online I came to know that the glob patterns are quite different. I did not found the pattern online which I was looking for. I have: a folder named…
luckyCasualGuy
  • 641
  • 1
  • 5
  • 15
0
votes
1 answer

pathlib absolute path misbehaving with config parser

I have a following python3 script, that uses the config function to load data from a txt file that sits in the same directory where the script is located. I've implemented the configparser module to extract the data, and pathlib module to set the…
0
votes
0 answers

I don't understand Python Solution I used to Glob multiple file types

So I need to parse and read files that have only "fip" or "frp" in them. Rather than just doing all full glob then using an if statment, I decided to search the webs on how I can achieve this. I stumbled on the answers here: Python glob multiple…
edo101
  • 629
  • 6
  • 17
0
votes
1 answer

How to zip contents of but not the folder

I am working with the following folder structure: . +-- temp | +-- sample1.csv | +-- sample2.csv +-- zips | +-- zip1.zip | +-- zip2.zip +-- main.py I want to zip the contents of the temp folder into a zip file, but I do not want to include…
0
votes
1 answer

Trying to print the stem (basename w/o extension) from a glob list

I'm trying to print the stem-only of each file in a glob list. The filenames are the names of people so I would like to just display their names without full path and extension. Any suggestions? I have looked at os.path but the pathlib.stem seemed…
ThomasATU
  • 572
  • 1
  • 5
  • 15
0
votes
1 answer

Why am I receiving an Illegal Instruction 4 when using Pathlib in Python?

I'm working on a project that watches my desktop using Watchdog, and sends a specified filetype to an external API that does some jiggery-pokery, then returns it to my desktop within a created folder. I'm using Python 3.8, and Pathlib's expanduser…
tomdot
  • 551
  • 6
  • 20
0
votes
1 answer

Is there a way to check access with pathlib?

I'm using pathlib now, which makes many things easier for me. But I'm still missing the os.access method. Is there a way to work around with pathlib? from os import access, R_OK from pathlib import Path def check_access(path): return…
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
0
votes
1 answer

If Statement Condition Met but Does Not Execute (Python)

HI I have a list of windows path objects which I am running an if statement on. Background: I have several csv files. My code checks these csv files. If csv file is good, the script moves the file to a dir called "archive". If there is an error its…
edo101
  • 629
  • 6
  • 17