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

  • Home
  • SEARCH
  • 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 8398681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:06:42+00:00 2026-06-09T21:06:42+00:00

I have a script that compiles few programs and puts the output into a

  • 0

I have a script that compiles few programs and puts the output into a folder, I have a function in my script that iterates and finds all the executables in the folder and adds them into a list,

def _oswalkthrough(direc,filelist=[]):
    dirList=os.listdir(direc)
    for item in dirList:
        filepath = direc+os.sep+item
        if os.path.isdir(filepath):
            filelist = _oswalkthrough(filepath,filelist)
        else:
            if ".exe" == item[-4:]:
                filelist.append(filepath)
    return filelist

This works with out any problem on windows, but when I run this on a mac, I can’t get it to work, of course the compiled files in mac doesn’t end with “.exe”, so that if statement is useless, so I made a list that contains the name of the compiled files and changed the script to the following, but still no result, it adds all the files, including the “.o” files, which I do not want!. I just want the exe? (I don’t know what they are called in mac !).

def _oswalkthrough(direc,filelist=[]):
    dirList=os.listdir(direc)
    for item in dirList:
        filepath = direc+os.sep+item
        if os.path.isdir(filepath):
            filelist = _oswalkthrough(filepath,filelist)
        else:
            for file in def_scons_exe:
                if file == item[-4:]:
                    filelist.append(filepath)
    return filelist
  • 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-09T21:06:43+00:00Added an answer on June 9, 2026 at 9:06 pm

    Looks like the section:

    for file in def_scons_exe:
        if file == item[-4:]:
            filelist.append(filepath)
    

    Should be:

    for file in def_scons_exe:
        if file == item[-len(file):]:
            filelist.append(filepath)
            break
    

    This change makes the program look for extensions of any length, not just 4 characters. It also stops looking through the extensions when it finds one that matches.

    Also, you should try using the os.walk function to simplify your code as well as os.access([path], os.X_OK) to test for execute permissions.

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

Sidebar

Related Questions

I have a little script that compiles a markdown file into html, and inserts
I have a script that recursively loops through all the sub directories and compresses
I have following script that executes all the .reg files in the current directory.
I have noticed quite a few times that syntax errors like Exit(push(ASBDD(asPixmap, _ScriptSavePixmap(Script, PMRGBAdjust(_ScriptGetPixmap(Script,
I have a script that compiles a list of items that can be very
I have bash script that work for many files in loop. It compiles, check
I have a NAnt script that compiles our web application, but would like to
I have script that reads remote file content and writes it to local server.
I have this script that run to fix my menu bar to the browser
I have a script that submits data via an ajax POST. It is called

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.