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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:24:03+00:00 2026-06-12T19:24:03+00:00

OS: Windows 7, 64-bit Python 3.1.3 When I try to do this os.listdir(F:\\music) I

  • 0
  • OS: Windows 7, 64-bit
  • Python 3.1.3

When I try to do this

os.listdir("F:\\music")

I get this

UnicodeEncodeError: 'gbk' codec can't encode character '\xe3' in position 643: illegal multibyte sequence

os.listdir works with other directories so the cause of the problem is obviously some strangely-encoded file or folder within F:\music itself. How do I find the source of this error?

  • 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-12T19:24:04+00:00Added an answer on June 12, 2026 at 7:24 pm

    UnicodeEncodeError indicates that you are trying to print the filenames. If it was os.lisdir() that had a problem you should see a UnicodeDecodeError (Decode, not Encode).

    Because you use a Unicode pathname, os.listdir() returns readily decoded filenames; on Windows the filesystem uses UTF-16 to encode filenames and those are easily decoded in Python (sys.getfilesystemencoding() tells Python what codec to use).

    However, the Windows console uses a different encoding; in your case gbk, and that codec cannot display all the different characters that UTF-16 can encode.

    You are looking for a print() statement here. You perhaps could use print(filename.encode('gbk', errors='replace')) to try and print the filenames instead; unprintable characters will be replaced by a question mark.

    Alternatively, you could use a b'F:\\music' as the path and work with raw bytestrings instead of Unicode.

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

Sidebar

Related Questions

[Windows 7 64 bit; Python 2.7] If I try to use Urllib2, I get
I just downloaded the latest Python IDLE 3.2 for Windows 7 (64-bit). I can
I am running 64-bit Windows 7 and the Python 2.6 installation (64-bit version). In
I am running 32-bit Windows 7 and Python 2.7. I am trying to write
I'm running 32-bit Windows 7 Enterprise and CodeBlocks 10.05. I followed this tutorial to
(Running MingW on 64-bit Windows 7 and the GCC on Kubuntu) This may possibly
I am running 64-bit Windows 7 and the ActiveState Python 2.5 installation (64-bit version).
I am using MinGW on a 64-bit Windows machine. I am using Python 2.6.8.
Running Python 3.2 on Windows 7 Pro 64 Bit. OK I have some very
I have a new 64-bit Windows machine and use python for various things and

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.