批处理文件脚本从文件名中删除特殊字符(视窗) [英] Batch file script to remove special characters from filenames (Windows)

查看:510
本文介绍了批处理文件脚本从文件名中删除特殊字符(视窗)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大集的文件,其中的一些包含在文件名特殊字符(例如,ö%,及其他)。我想一个脚本文件来遍历这些文件并重新命名去除特殊字符。我不介意它做什么,但它可以用下划线例如例如替换它们。

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将被重命名为St_rung_20.doc

Störung%20.doc would be renamed to St_rung_20.doc

在preference的顺序为:

In order of preference:


  1. DOS批处理文件

  2. Windows脚本文件cscript的运行(VBS)

  3. 一个第三方的软件,可以在命令行中运行(即无需用户交互)

  4. 另一种语言的脚本文件,为此我不得不安装一个额外的脚本引擎

背景:我想这些加密文件使用GnuPG在Windows上,但它似乎并没有与--encrypt-文件选项文件名来处理特殊字符

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.

这个问题似乎是由GPG使用的codePAGE是固定的(拉丁文I)独立于控制台中配置的codePAGE的。但是,一旦他指出了这一点,我想出如何workaraound这一点。

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.

关键是生成文件列表前更改codePAGE。这实际上使文件列表似乎是不正确的控制台查看时。但是,传递给GPG时,它工作正常。 GPG接受的文件和吐出用正确的文件名encrytped文件。

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:

chcp 1252
dir /b /s /a-d MyFolder >filelist.txt
gpg -r test@test.com --encrypt-files <filelist.txt

这篇关于批处理文件脚本从文件名中删除特殊字符(视窗)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆