Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to input multiple files from a directory

Tags:

python

unix

xml

First and foremost, I am recently new to Unix and I have tried to find a solution to my question online, but I could not find a solution.

So I am running Python through my Unix terminal, and I have a program that parses xml files and inputs the results into a .dat file.

My program works, but I have to input every single xml file (which number over 50) individually.

For example:

clamshell: python3 my_parser2.py 'items-0.xml' 'items-1.xml' 'items-2.xml' 'items-3.xml' .....`

So I was wondering if it is possible to read from the directory, which contains all of my files into my program? Rather than typing all the xml file names individually and running the program that way.

Any help on this is greatly appreciated.

like image 987
Yozuru Avatar asked Jan 23 '26 12:01

Yozuru


1 Answers

import glob

listOffiles = glob.glob('directory/*.xml')
like image 139
LetzerWille Avatar answered Jan 25 '26 01:01

LetzerWille



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!