Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:25:43+00:00 2026-05-28T07:25:43+00:00

I have an XML file named junit.xml in the same directory as my script,

  • 0

I have an XML file named junit.xml in the same directory as my script, I can parse it by doing:

xml_file = os.path.abspath(__file__)
xml_file = os.path.dirname(xml_file)
xml_file = os.path.join(xml_file, "junit.xml")
root = ET.parse(xml_file).getroot();  # Where ET is the element tree

and everything is ok.

However, I have a more complex example where I need to parse a bunch files with the same name “junit.xml” that are in different directories in succession.

The directories are as follows:

\myhome\ireland\modules\builds\date1
\myhome\ireland\modules\builds\date2
\myhome\england\modules\builds\date1
\myhome\england\modules\builds\date2
\myhome\scotland\modules\builds\date1
\myhome\scotland\modules\builds\date2
\myhome\wales\modules\builds\date1
\myhome\wales\modules\builds\date2
\myhome\germany\modules\builds\date1
\myhome\germany\modules\builds\date2

Now, each directories has collection of XML files. I just want to get all the files named junit.xml under:

\myhome\ireland\modules\builds\date2
\myhome\england\modules\builds\date2
\myhome\scotland\modules\builds\date2

How can I do this in a pythonic way, where I can vary the names of the countries and the date when I need to?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:25:44+00:00Added an answer on May 28, 2026 at 7:25 am

    Use a string template for the path, for example:

    path = r"\myhome\{}\modules\builds\date{}"
    

    Which you can later use to construct the real path using the str.format() function (e.g. path.format("ireland", 1)).

    Then, you can iterate over the country names and dates, and for each one parse the XML file:

    for country in ["ireland", "england", "scotland"]:
        for num in [1, 2]:
            parse_xml(path.format(country, num))
    

    Where parse_xml is a function you define which gets a path to an XML file and parses it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a compiled .NET assembly with a specific resource file embedded (named 'Script.xml').
I have a bit of xml file named Sample.xml which is shown below <?xml
Let's say I have an existing trivial XML file named 'MyData.xml' that contains the
I have an XML document as follows: <directory> <file><monitored>0</monitored> <xferStatus>1</xferStatus> <name>test1.txt</name> <size>7</size> <created>03/31/10 11:30:02
I am running windows application in vb.net.I have a xml file named mail.xml in
I have this problem where all URLs like context/path/file/anything/that/follows becomes context/path/file.php/anything/that/follows or context/path/file.xml/anything/that/follows .
I have a method named GetOrders . This method reads an XML file and
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
I have an xml file like this: <result> <customer> <id>1</id> <name>A</name> </customer> <customer> <id>2</id>
i have a file Accelerator.xml <?xml version=1.0 encoding=UTF-8?> <os:openServiceDescription xmlns:os=http://www.microsoft.com/schemas/openservicedescription/1.0> <os:homepageUrl>http://www.sapo.pt</os:homepageUrl> <os:display> <os:name>Find on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.