I have a large set of files, some of which contain special characters in the filename (e.g. ä,ö,%, and others). I'd like a script file to iterate over these files and rename them removing the special characters. I don't really mind what it does, but it could replace them with underscores for example e.g.
Störung%20.doc would be renamed to St_rung_20.doc
In order of preference:
- A Windiws batch file
- A Windows script file to run with cscript (vbs)
- A third party piece of software that can be run from the command-line (i.e. no user interaction required)
- Another language script file, for which I'd have to install an additional script engine
Background: I'm trying to encrypt these file with GnuPG on Windows but it doesn't seem to handle special characters in filenames with the --encrypt-files option.
Thanks to Tomalak who actually pointed me in the right direction. Thought I'd post here for completeness.
The problem seems to be that the codepage used by GPG is fixed (Latin I) independent of the codepage configured in the console. But once he pointed this out, I figured out how to workaraound this.
The trick is to change the codepage before generating the file list. This will actually make the filelist appear to be incorrect when viewed in the console. However, when passed to GPG, it works fine. GPG accepts the files and spits out the encrytped files with correct filenames.
The batch file looks something like this:
Have you tried setting cmd.exe into another codepage before you feed the file names to gnupg? Issue
chcp 65001
to set cmd.exe to Unicode beforehand and try again.If that fails, the following VBScript would do it:
call it like this:
You can also drag&drop a folder onto it in Windows Explorer.
From http://www.robvanderwoude.com/bht.html:
use NT's SET's string substitution to replace or remove characters anywhere in a string:
If you use this attempt, you will have to process each character you want to replace (e.g. Ä,Ö,Ü,ä,ö,ü,ß, but also á,à,é,è...) seperately.
Following 'RenameFilesWithAccentedAndDiacriticalLatinChars.pl' PERL script renames files with accented and diacritical Latin characters :
Option '--batch' avoids interactive questions. Use with care.
Option '--' avoids the next parameter to be interpreted as option.
Special Warning :
I'm using this batch to rename folders and seems to work fine so far... In my case codepage is 1252, yours might be different.