Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get filename from path

import os
print(os.path.basename(your_path))
Comment

get filename from path python

from pathlib import Path
>>> p = r"C:UsersshaliOneDrivecodesetTheory.pdf"
>>> Path(p).anchor
'C:'
>>> Path(p).parent
WindowsPath('C:/Users/shali/OneDrive/code')
>>> Path(p).name
'setTheory.pdf'
>>> Path(p).stem
'setTheory'
>>> Path(p).suffixes
['.pdf']
Comment

Extract filename from path in Python

filename = os.path.basename("path/to/file/sample.txt")
Comment

python get filename from path

print (os.path.basename("/path/to/file.txt"))
# file.txt
Comment

extract name of file from path python

from pathlib import Path
Path("/tmp/d/a.dat").name
Comment

PREVIOUS NEXT
Code Example
Python :: how to change index in dataframe python 
Python :: pandas filter rows that are in a list 
Python :: planet 
Python :: fetch data from excel in python 
Python :: get user django 
Python :: python program to find numbers divisible by another number 
Python :: import yaml python3 
Python :: Upper letter list 
Python :: python numpy array 
Python :: hungarian algorithm python 
Python :: export flask app 
Python :: import all csv python 
Python :: pyttsx3 save audio 
Python :: python uppercase 
Python :: machine learning python 
Python :: sum of list in python 
Python :: python positional argument follows keyword argument 
Python :: python download file from ftp 
Python :: nice python turtle code 
Python :: while true python 
Python :: insert row at given position in pandas dataframe 
Python :: how to create background images in tkinter 
Python :: make sns heatmap colorbar larger 
Python :: python print error output 
Python :: how to print specific part of a dictionary in python 
Python :: python trim leading whitespace 
Python :: fibonacci series using dynamic programmig approach 
Python :: convert list to tuple python 
Python :: python first three characters of string 
Python :: python decimal remove trailing zero 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =