I want to retrieve the filenames of all the files with .xml extension present in various subfolders in a single directory,
Asked
Active
Viewed 200 times
-2
-
1Have you done anything so far or you are expecting that someone will do all the work instead of you? – zero323 Sep 16 '13 at 14:04
2 Answers
0
Use os.walk
, and str.endswith
.

Thomas Orozco
- 53,284
- 11
- 113
- 116
-
I was able to retrieve all the files from the Sub-Directories. Thanks for your support. Some directories contain a mixed bag of files, for e.g. .py files, .txt files and .xml files ofcourse, Also the naming convention of the files are 02.01 Abc.xml, 3.5 def.xml, 02.05 Abc.py, Initialization.txt. Now I want to retrieve all those files which has numerals in the first two places of the name and are xml, i.e. .xml extension), does not really matters what comes in between. I used a regex. 'Names' contain all the names of the files matchgroup = re.match(r'^\d\d[xml]$', Names, re.M): Need assist. – user1227670 Sep 17 '13 at 19:35
-
I was able to retrieve all those files with two numerals in the begining and also .xml extension. Thanks for your support. I have placed all those names in an .xml file. Now I want to convert those filenames in a hyper-reference to some files located on the same machine. Line of Code of Regular Expression: re.match(r'^\d\d(.*)\xml$', names, re.M): Line of Code to display the name in the xml. a.write(
with a as the stream. Need inputs in this case. – user1227670 Sep 19 '13 at 13:26
0
code:
import os
xmlFiles = []
for directoryPath in os.walk(filePath):
fileName = directoryPath[2]
if fileName[:3] = 'xml':# or fileName.endswith('xml'):
xmlFiles.append(fileName)

Henri Korhonen
- 134
- 5
-
I was able to retrieve all the files from the Sub-Directories. Thanks for your support. – user1227670 Sep 17 '13 at 19:20
-
No problem but little vote up button or selecting answer wouldn't hurt ;D – Henri Korhonen Sep 17 '13 at 19:44
-
I was able to retrieve all those files with two numerals in the begining and also .xml extension. Thanks for your support. I have placed all those names in an .xml file. Now I want to convert those filenames in a hyper-reference to some files located on the same machine. Line of Code of Regular Expression: re.match(r'^\d\d(.*)\xml$', names, re.M): Line of Code to display the name in the xml. a.write(
with a as the stream. Need inputs in this case. – user1227670 Sep 19 '13 at 13:27 -