1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Batch file to rename accented characters

Discussion in 'Windows XP' started by Topio, May 7, 2010.

Thread Status:
Not open for further replies.
  1. Topio

    Topio Thread Starter

    Joined:
    May 7, 2010
    Messages:
    1
    I create batch files to rename many files at a time
    they work ok but whenever i try to rename a file with an accented character
    i.e. the following line

    ren "c:\expresión\méxico.txt" "mexico-file.txt"

    produces the following error

    "File Not Found" even though I'm pretty sure the file is there
     
  2. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Welcome to TSG!

    The Command Prompt uses a different codepage (list of characters) than Windows does, so the characters don't match. The accented é typed into a batch file in notepad is not the same character that the Command Prompt sees. Dir shows the é but when run in a batch file it doesn't match.
    To work, you need to change the codepage in your batch file.
    The Command Prompt uses codepage 437 usually (type Chcp at the prompt to see which is being used), Windows uses 1252 for Latin based languages in most locales.
    This will save the current codepage, change it, rename the file, then change it back. You can also make an entry in the registry so the Command Prompt will always open using the 1252 codepage if needed.

    Code:
    For /F "Tokens=2 Delims=:" %%I In ('Chcp ') Do Set /A _CurCP=%%I
    Chcp 1252
    ren "c:\expresión\méxico.txt" "mexico-file.txt"
    Chcp %_CurCP%
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Batch file rename
  1. iono
    Replies:
    0
    Views:
    291
  2. xyl3
    Replies:
    8
    Views:
    590
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/921553

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice