Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get name of file

file_name = os.path.basename(file_path)
Comment

get the name of a file using os

>>> list_of_names_in_directory = os.listdir('path/of/directory')
Comment

get name of a file in python

>>> f = open('/tmp/generic.png','r')
>>> f.name
'/tmp/generic.png'
>>> import os
>>> os.path.basename(f.name)
'generic.png'
Comment

os.filename

import os
file_location = '/srv/volume1/data/eds/eds_report.csv'
file_name = os.path.basename(file_location )  #eds_report.csv
location = os.path.dirname(file_location )    #/srv/volume1/data/eds
Comment

os.filename

import os
file_location = '/srv/volume1/data/eds/eds_report.csv'
file_name = os.path.basename(file_location )  #eds_report.csv
location = os.path.dirname(file_location )    #/srv/volume1/data/eds
Comment

PREVIOUS NEXT
Code Example
Python :: intersection between two arrays using numpy 
Python :: how to resize windows in python 
Python :: python get desktop directory 
Python :: change python3 as default for mac 
Python :: how to find the datatype of a dataframe in python 
Python :: median of a list in python 
Python :: python replace char in string 
Python :: pip install for python 2 and python3 
Python :: check where bool in a list python 
Python :: how to make a countdown in pygame 
Python :: read excel into dataframe python 
Python :: spyder - comment banch of codee 
Python :: create a dictionary in python 
Python :: pyspark show all values 
Python :: pandas iterrows 
Python :: # time delay in python script 
Python :: python glob 
Python :: timestamp to date time till milliseconds python 
Python :: templateDoesNotExist Django 
Python :: select non nan values python 
Python :: pandas delete column by name 
Python :: terms for list of substring present in another list python 
Python :: python range in reverse order 
Python :: python remove punctuation from text file 
Python :: qrcode.make python 
Python :: lexicographic order python 
Python :: remove keys from dict python 
Python :: how to get images on flask page 
Python :: migrate data django 
Python :: python remove duplicate numbers 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =