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 8413855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:00:45+00:00 2026-06-10T01:00:45+00:00

I am new to python and I have trouble accessing the math text-files within

  • 0

I am new to python and I have trouble accessing the math text-files within the subfolders.

                    Hierarchy of the folder

This is the code I have written so far:

import os, sys
for folder, sub_folders, files in os.walk(my_directory):
   for special_file in files:
      if special_file == 'math.txt'
         file_path = os.path.join(folder, special_file)
         with open(file_path, 'r+') as read_file
            counter += 1
            print('Reading math txt file' + str(counter))

            for line in read_file:
               print(line)

I am not able to do print lines of all the math.txt files within all the classes and all the schools and all the zones.

Before I had a version of the script that merged all the files, but some of the log files were extremely large (combined > 16GB).

  • 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-06-10T01:00:47+00:00Added an answer on June 10, 2026 at 1:00 am

    This seems to work for me. Only changes were those that @jdi, @MRAB and I were indicating – missing colons and initializing the counter variable. Since you’re on Windows, you may want to make sure that you’re properly specifying your directory path.

    import os, sys
    
    # Specify directory
    # In your case, you may want something like the following
    my_directory = 'C:/Users/<user_name>/Documents/ZoneA'
    
    # Define the counter
    counter = 1
    
    # Start the loop
    for folder, sub_folders, files in os.walk(my_directory):
      for special_file in files:
        if special_file == 'math.txt':
          file_path = os.path.join(folder, special_file)
    
          # Open and read
          with open(file_path, 'r+') as read_file:
            print('Reading math txt file ' + str(counter))
    
            # Print the file
            for line in read_file:
               print(line)
    
            # Increment the counter
            counter += 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new in python programming. just got stuck with this one problem. I have
I am very new with Python and I have just received this message while
I'm kinda' new to python, but I have already written many programs including some
I am new to Python and I have trouble to import modules with Wing
I am new to Python and have been studying its fundementals for 3 months
I'm new to python and have hit a problem with an SQL query I'm
hello im new to python and have been reading over the documentation and am
I am very new to python programming and have yet to buy a textbook
I am very new to Python and I have a json news feed that
I am new to python and I have a serious problem that I cannot

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.