glob - How does one get all files in a directory with a specific pattern in their names in Python -


i need filenames directory specific ending. files want directory have same name different numbers, other files exist in same directory. files numbered in following format:

project_name_1.txt project_name_2.txt project_name_3.txt project_name_14.txt project_name_19.txt project_name_31.txt  

the number of files can vary. , file names (apart numbering) user dependent. i'm looking following:

[s s in os.listdir(directory) if "*_*.txt" in s ] 

or

glob.glob(directory, '*_?.txt') 

how about

name = 'project_name' glob.glob(os.path.join(directory, '{}_*.txt'.format(name))) 

this lets files "project_name_something.txt" through, want check them afterwards.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -