I need to retrieve all the filenames ending with .xml extension from all the subdirectories present in a directory and copy those names into a new .xml file.

Have look at the os.walk() function.

I assume you need the full pathname of each file.

Python module glob will help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.