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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:23:52+00:00 2026-05-13T14:23:52+00:00

I have a piece of code which I’m using to search for the executables

  • 0

I have a piece of code which I’m using to search for the executables of game files and returning the directories. I would really like to get some sort of progress indicator as to how far along os.walk is. How would I accomplish such a thing?

I tried doing startpt = root.count(os.sep) and gauging off of that but that just gives how deep os.walk is in a directory tree.

def locate(filelist, root=os.curdir): #Find a list of files, return directories.
    for path, dirs, files in os.walk(os.path.abspath(root)):
        for filename in returnMatches(filelist, [k.lower() for k in files]):
            yield path + "\\"
  • 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-13T14:23:53+00:00Added an answer on May 13, 2026 at 2:23 pm

    I figured this out.

    I used os.listdir to get a list of toplevel directories, and then used the .split function on the path that os.walk returned, returning the first level directory that it was currently in.

    That left me with a list of toplevel directories, which I could find the index of the current directory of os.walk, and compare the index returned with the length of the list, giving me a % complete. 😉

    This doesn’t give me a smooth progress, because the level of work done in each directory can vary but smoothing out the progress indicator is of no concern for me. But it could easily be accomplished by extending the path checking deeper into the directory structure.

    Here is the final code from getting my progress:

    def locateGameDirs(filelist, root=os.curdir): #Find a list of files, return directories.
        toplevel = [folder for folder in os.listdir(root) if os.path.isdir(os.path.join(root, folder))] #List of top-level directories
        fileset = set(filelist)
    
        for path, dirs, files in os.walk(os.path.abspath(root)):
    
            curdir = path.split('\\')[1] #The directory os.walk is currently in.
    
            try: #Thrown here because there's a nonexistant(?) first entry.
                youarehere = toplevel.index(curdir)
                progress = int(((youarehere)/len(toplevel))*100)
            except:
                pass
    
            for filename in returnMatches(filelist, [k.lower() for k in files]):
                yield filename, path + "\\", progress
    

    And right now for debugging purposes I’m doing this further in the code:

        for wow in locateGameDirs(["wow.exe", "firefox.exe", "vlc.exe"], "C:\\"):
        print wow
    

    Is there a nice little way to get rid of that try/except?; it seems the first iteration of path gives me nothing…

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

Sidebar

Related Questions

I have this piece of code which works, however I would like to change
Hi all I have a piece of code which looks like this: public class
I have a piece of code which looks like this: Snippet A: class Creature
I have inherited a piece of code which has a series of functions like
I have this piece of code which i am using on another area of
I would like to implement a shuffle function, I have this piece of code
I have some piece of code which goes like this: pipe(fd); child_map[0] = fd[0];
In JCIP we have a piece of code which looks like this: Listing 4.2:
I have this piece of code which plays my mp3 files on my iphone
If I have a piece of code which does something like this. try {

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.