Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pathlib:file in a directory
#1
i have a reference to a pathlib.Path object that is a reference to a file system object that may not exist. also, i have a reference to a pathlib.Path object that is a reference to a directory that may not exist (in which case, by itself, it is not really known that it is a directory). i want to determine if that file system object is (or would be) in (at any level of depth) that directory. i could get strings of both, verify that the object path string begins with the whole directory string and has a '/' next (in my case, this is always Posix). but could there be ways a Path object can do this better (such as a Pythonic way or a portable way)?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Perhaps the PurePath.relative_to() method?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with pathlib ? Ota 3 1,351 Nov-11-2024, 06:04 AM
Last Post: MoMoProxy
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 958 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 6,418 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 7,903 Jun-27-2023, 01:17 PM
Last Post: diver999
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 4,004 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 2,027 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 2,622 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
Photo Making Zip file of a file and Directory Nasir 2 1,792 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Failed to execute child process (No such file or directory) uriel 1 2,385 Sep-15-2022, 03:48 PM
Last Post: Gribouillis
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 5,974 Sep-12-2022, 04:50 AM
Last Post: python202209

Forum Jump:

User Panel Messages

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