Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I convert garbled filenames (Chinese) to the correct codepage?

How can I convert garbled filenames (Chinese) to the correct codepage?

Scheduled Pinned Locked Moved C#
helpquestioncsharpworkspace
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alien05
    wrote on last edited by
    #1

    On disk sometimes I have filenames that show up like ûÓÐÈË¿ÉÒÔ½ÐÄ㱦±´. However it should really be this: 没有人可以叫你宝贝. (Others are displayed correctly, so it is not a problem of the system). I can copy the garbaged filename to a text file, open it in a browser, change the codepage to gb2312 for display in the browser, copy the displayed Chinese characters and rename the file. (I currently do not see through what the browser does) This is not applicable for more than a few files. So I want to automate it. (I have a european Windows XP environment, should be the same with English) Is there any tool, that does it? Or how can I do what the browser can do by C# coding? (the encoding part is sufficient). Tried the encoding class but did not get any usable result. Please help. Thanks.

    F 1 Reply Last reply
    0
    • A alien05

      On disk sometimes I have filenames that show up like ûÓÐÈË¿ÉÒÔ½ÐÄ㱦±´. However it should really be this: 没有人可以叫你宝贝. (Others are displayed correctly, so it is not a problem of the system). I can copy the garbaged filename to a text file, open it in a browser, change the codepage to gb2312 for display in the browser, copy the displayed Chinese characters and rename the file. (I currently do not see through what the browser does) This is not applicable for more than a few files. So I want to automate it. (I have a european Windows XP environment, should be the same with English) Is there any tool, that does it? Or how can I do what the browser can do by C# coding? (the encoding part is sufficient). Tried the encoding class but did not get any usable result. Please help. Thanks.

      F Offline
      F Offline
      Frank Horn
      wrote on last edited by
      #2

      That's interesting. I'm not sure what the problem is though. Just created a file named 没有人可以叫你宝贝.txt on a German XP (hope it doesn't mean anything nasty), and in Explorer it shows up as a sequence of squares. This looks like a system thing indeed, cause the file name is correct (as I can see when I drag it into Firefox, which shows 没有人可以叫你宝贝.txt in the address bar). Is this the phenomenon you mean, or do your files also have a different name? And if so, can you reproduce it?

      A 1 Reply Last reply
      0
      • F Frank Horn

        That's interesting. I'm not sure what the problem is though. Just created a file named 没有人可以叫你宝贝.txt on a German XP (hope it doesn't mean anything nasty), and in Explorer it shows up as a sequence of squares. This looks like a system thing indeed, cause the file name is correct (as I can see when I drag it into Firefox, which shows 没有人可以叫你宝贝.txt in the address bar). Is this the phenomenon you mean, or do your files also have a different name? And if so, can you reproduce it?

        A Offline
        A Offline
        alien05
        wrote on last edited by
        #3

        Did you install your Windows' option "support for East Asian languages"? If so the filename should display as I have posted before. If you are using Tools instead of the Windows Explorer, it might be that they are not able to display double byte characters and will display symbols instead. Total Commander should work with it but some of its functions do not.

        F 1 Reply Last reply
        0
        • A alien05

          Did you install your Windows' option "support for East Asian languages"? If so the filename should display as I have posted before. If you are using Tools instead of the Windows Explorer, it might be that they are not able to display double byte characters and will display symbols instead. Total Commander should work with it but some of its functions do not.

          F Offline
          F Offline
          Frank Horn
          wrote on last edited by
          #4

          No, I have no support for Asiian languages installed. Anyway, if it's actually about encoding, did you try something like this:

          string source = "ûÓÐÈË¿ÉÒÔ½ÐÄ㱦±´";

          Encoding sourceEncoding = Encoding.Default;
          byte[] bytes = sourceEncoding.GetBytes(source);

          Encoding targetEncoding = Encoding.GetEncoding("gb2312");
          string target = targetEncoding.GetString(bytes);

          A 1 Reply Last reply
          0
          • F Frank Horn

            No, I have no support for Asiian languages installed. Anyway, if it's actually about encoding, did you try something like this:

            string source = "ûÓÐÈË¿ÉÒÔ½ÐÄ㱦±´";

            Encoding sourceEncoding = Encoding.Default;
            byte[] bytes = sourceEncoding.GetBytes(source);

            Encoding targetEncoding = Encoding.GetEncoding("gb2312");
            string target = targetEncoding.GetString(bytes);

            A Offline
            A Offline
            alien05
            wrote on last edited by
            #5

            Thanks a lot! That seems to work. My problem was, that I did not find Encoding.Default. Had tried all others, but .Default is obviously the remedy.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups