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
0 answers

pathlib and cytpes loadlibrary

I have a python package, mymodule, that contains a shared library file and an init.py file. The init.py file declares various functions and also loads the shared library file: lib = ctypes.cdll.LoadLibrary('mydll') I want the user to be able place…
Andy
  • 131
  • 8
0
votes
1 answer

iterating over folders executing a fuction at each 2 folders

I have a function called plot_ih_il that receives two data frames in order to generate a plot. I also have a set of folders that each contain a .h5 file with the data I need to give to the function plot_ih_il... I'm trying to feed the function two…
hcp
  • 319
  • 2
  • 16
0
votes
2 answers

Access Directory with Account and Password

I am using python lib - Pathlib to access a file in the directory which requires Acc & Pwd. Following is my current code: FILE_PATH = "//192.168.10.1/Test/test.xlsx" fileDir = pathlib.Path(FILE_PATH) if (fileDir.exists() == False): …
W Kenny
  • 1,855
  • 22
  • 33
0
votes
1 answer

How to remove a file from Path object in Pathlib module?

I have a Path Object representing C:\Users\users\Downloads\img.jpg. How do I get it so the Path only represents C:\Users\user\Downloads? I don't want to delete the file, but rather go back in the Path object itself. from pathlib import Path path =…
0
votes
2 answers

Whats the explanation for this behaviour?

from pathlib import Path file = Path(r"C:\Users\SerT\Desktop\a.txt") print (file.name) file.rename(file.with_name("b.txt")) print (file.name) i'd like to know why file.name prints out "a.txt" in both instances even though the file actually gets…
Ser.T
  • 51
  • 4
0
votes
0 answers

i'm writing this program to print out the names of all mp3 files in a particular folder and it encounters this error message

from pathlib import Path song_folder = Path(r"C:\Users\Tito\Music\Songs\1") for song in song_folder.glob("*.mp3"): print (song.name) File "c:\Users\Tito\Documents\VS code\music_sort4.py", line 10, in print (file) File…
Kun.tito
  • 165
  • 1
  • 7
0
votes
0 answers

Dynamically creating file upload path in Flask results in 'None' directory being created

I've got a simple flask app that takes form input from the user in addition to file uploads. I can get the files uploaded to a directory on the disk just fine, but the problem I'm running into is that when multiple users try to upload files, all the…
0
votes
2 answers

Get a file that is in a folder that is a child of the parent directory with python

I have attempted this heavily but have found no way to do this, I think I am not understanding something. Here is my tree of the .bat that runs it: https://i.stack.imgur.com/lrpvG.png and here is my 'src' folder:…
user13653977
0
votes
1 answer

Pathlib is taking an os.PathLike object, and interpereting it as bool

The Problem The project I'm currently working on has an inexplicable error, which either I'm too dumb to figure out, or is just that obscure and technical. I'm trying to first locate a directory, returning the path to it, and then checking if a…
0
votes
1 answer

Need some help understanding current working directory in pathlib

I am learning pathlib in Python. I create a script, printcwd.py: from pathlib import Path mypath = Path() print (mypath.cwd()) This will give me the result I expect if I run the python script by double clicking it inside any folder - it will…
Dude
  • 145
  • 1
  • 9
0
votes
0 answers

Pathlib: how to remove first n characters of path.stem

To the point: In a python script with YAML syntax I want to rename a file using: {created.year}-{created.month:02}-{created.day:02}_{path.stem}.jpg Would it be possible to remove the first n characters of path_stem? If so, how? Thank you!
0
votes
1 answer

Python replace Double Backlash with Single Bcklash

I am trying to convert the window path in Pathlib to string. However, I can't convert the \\ to \ The code I ran fileDir = pathlib.Path(self.CURRENTDATAPATH) fileExt = r"*.xlsx" for item in…
W Kenny
  • 1,855
  • 22
  • 33
0
votes
1 answer

How can I use Pathlib for configuring the settings for the project in Django/Faker?

Right now I'm trying to put some fake data in my database using Faker just for the checking purposes. I've created separate file, but before starting to work with Faker itself and data manipulation, I need to configure the settings for the project…
0
votes
1 answer

Generating File Paths for all files in folder structure

I wanted to generate URLs for all files in a folder hierarchy for path, folder, files in os.walk("C:/Users/guptamols/Course/tutorials"): for names in files: …
Gupta
  • 314
  • 4
  • 17
0
votes
1 answer

How to get absolute path of python file REGARDLESS of where it is run from

I'm trying to get the absolute path to a python file that I run from terminal regardless of WHERE I am in the filesystem when I run that file. So far I've looked at this, but the answers using pathlib don't work, as I'm about to…
WalksB
  • 498
  • 2
  • 14