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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:11:34+00:00 2026-06-09T04:11:34+00:00

Here is what I have so far in Windows: import os os.chdir(C:/Users/any/Desktop/test) for files

  • 0

Here is what I have so far in Windows:

    import os
os.chdir("C:/Users/any/Desktop/test")
for files in os.listdir("."):

    print files

Now it prints this:

test picture.jpg
test script.bat
test text.txt

But now where I am stuck is the output is going to be random with each folder done so my idea of a solution is to have it take the list and label each one individually as

filename1 
filename2
filename3

So now filename1 = test picture.jpg

Edit

Well what I am trying to do is later in my code each filename will be used for example say I was trying to rename my files so that any of those files that contained the letter ‘e’ in it, it would be changed to an ‘a’ character:

import os
os.chdir("C:/Users/any/Desktop/test")
for files in os.listdir("."):

    print files



files = files.replace('e', 'a')
print files

But I need to be able to have it do each filename individually so the code could look something like this:

import os
    os.chdir("C:/Users/any/Desktop/test")
    for files in os.listdir("."):

        print filename1



    filename1 = filename1.replace('e', 'a')
    print filename1
  • 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-09T04:11:36+00:00Added an answer on June 9, 2026 at 4:11 am

    While I am not 100% sure I understand what you are trying to do, you could just try this:

    dirlist = os.listdir('.')
    

    then each index, starting with zero, of dirlist would yield an entry from your directory. The index values would in effect take the place of the numbers for your filenames.

    So rather than having

    filename1 
    filename2
    filename3
    

    you’d have

    dirlist[0]
    dirlist[1]
    dirlist[2]
    

    with minimal effort, and could easily refer to individual entries in any order with the index.

    And as an added bonus, you could easily iterate through this list of names with a for-loop if need be

    for names in dirlist:
       ...
    

    which would be a bit more tricky with the individual filenames you mentioned in your original post.

    Update:

    Given your edit to your post, you would have been able to achieve your goal with pretty much your original code:

    import os
    os.chdir("C:/Users/any/Desktop/test")
    for fname in os.listdir("."):
        fname = fname.replace('e', 'a')
        print fname
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is what I have so far : def mergesort[T <: Ordered[T]](elements : List[T])
http://pastebin.com/mYk8M038 here is what I have so far... I think it may be something
I'm using the Firefox Add-on Builder and here is what I have so far:
I'm fairly new to JS, here's what I have so far. I can get
I'm a total newb to LINQ. Here is the code I have so far:
Here is what I have tried thus far: > cd /Applications/MAMP/bin/php5/bin/ > ./pear channel-discover
I really wonder why this question hasn't popped up here so far. I have
I have been searching for several hours now and have so far had no
Here's a barebones Python app that simply prints the command-line arguments passed in: import
Here are the steps I have followed so far, with no luck. I am

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.