Python Forum
How to get file name without the full path details and without extension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get file name without the full path details and without extension
#2
Here are a few options:
filename = Path(...)
assume filename = /.../.../myfile.txt
to get just filename: print(filename.name) result: myfile.txt
to get full path: print(filename.resolve()) result /.../.../myfile.txt
to get just the stem: print(filename.stem result myfile
to get suffix: print(filename.suffix result: .txt
to get absolute path broken into tuples: filename.resolve().parts
Reply


Messages In This Thread
RE: How to get file name without the full path details and without extension - by Larz60+ - Jan-13-2020, 07:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  File path by adding various variables Mishal0488 2 1,038 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Script File Failure-Path Error? jerryf 13 3,468 Nov-30-2022, 09:58 AM
Last Post: jerryf
  How to add product details in exe generated by pyinstaller arex786 1 8,493 Oct-10-2021, 11:00 AM
Last Post: Sran012
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,215 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,096 May-07-2021, 03:26 PM
Last Post: herwin
  How to make a test data file for the full length of definition? MDRI 6 3,554 Apr-16-2021, 01:47 AM
Last Post: MDRI
  Add file to sys.path permanently hcccs 5 8,412 Jan-31-2021, 11:26 AM
Last Post: hcccs
  find file not knowing the extension Leon79 6 3,098 Jul-07-2020, 04:44 PM
Last Post: Leon79
  Can't open/read txt file in C extension for Python Rad226 8 4,795 Jun-26-2020, 04:08 PM
Last Post: Rad226
  How to append a tuple full of records to a dbf file in Python? DarkCoder2020 4 3,746 May-29-2020, 02:40 PM
Last Post: DarkCoder2020

Forum Jump:

User Panel Messages

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