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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:44:45+00:00 2026-06-01T16:44:45+00:00

I build totalset = {} and extract the file names from folders A, B,

  • 0

I build

totalset = {} 

and extract the file names from folders A, B, C, D by

for file_name in (os.listdir(full_subdir_name)):
    full_file_name = os.path.join(full_subdir_name, file_name)

Now I want to build something called namelist that contains all the file names, and I could traverse all the files in the folders through:

for file in namelist[A]:
    blabla...

for file in namelist[B]:
    blabla.. .  

What should I do?

  • 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-01T16:44:46+00:00Added an answer on June 1, 2026 at 4:44 pm

    You should probably use a “list comprehension”. Here is an example of how you could do it:

    lst_names = [os.path.join(full_subdir_name, n) for n in os.listdir(full_subdir_name)]
    

    So then you would build the full namelist something like this. First you should set up a list of names.

    # example using Windwows filenames
    # note that we use "raw strings" with r'' so the backslash will not be weird
    lst_names = [r'C:\Users\steveha\Desktop', r'C:\Users\steveha\Documents', r'C:\Users\steveha\Music']
    
    # example using Mac or Linux filenames
    lst_names = ['/home/steveha/Desktop', '/home/steveha/Documents', '/home/steveha/Music'
    

    Once you have lst_names set up with your names, build the full namelist:

    namelist = {}
    
    for full_subdir_name in lst_names:
        namelist[full_subdir_name] = [os.path.join(full_subdir_name, n) for n in os.listdir(full_subdir_name)]
    

    Personally I think it would be easier to read with a shorter variable name than full_subdir_name:

    namelist = {}
    
    for f in lst_names:
        namelist[f] = [os.path.join(f, n) for n in os.listdir(f)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I build a coustom listview, wich filled with data from SQLite. Now I want
After build, I need to modify an HTML file that points the client to
TFS Build 2010 is completely different from 2008. There is no Exec task -
My build process builds and copies a .war file to $TOMCAT_HOME/webapps. 75% or more
I build a CFG out of an arbitrary IL and want to convert that
I build a .NET Class Library project that accesses the mshtml.HTMLDocument when called (from
i build an application how take Pcap file (wireshark file) and play the packets,
Goal: Build an Android app that discovers the names and addresses of BT devices
i build application android....and i want to back up my database when user click
I build and sign my android app. Now I publish on google play but

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.