windows 重命名文件并删除“点”并将其替换为“_”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6626343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Renaming a file and remove 'dot' and replace it with' _'
提问by deepa
I have set of files in a folder with name like abcd.15678 I want to remove the . and replace it with _
我在名为 abcd.15678 的文件夹中有一组文件我想删除 . 并将其替换为 _
Pls suggest the windows command to do this
请建议使用 windows 命令来执行此操作
回答by tskuzzy
Something like this? Batch file script to remove special characters from filenames (Windows)
回答by Eptin
This solution is reposted from How to Batch Rename Files in Windows: 4 Ways to Rename Multiple Filesby Chris Hoffman
此解决方案是从How to Batch Rename Files in Windows: 4 Ways to Rename Multiple Filesby Chris Hoffman 重新发布的
PowerShell offers much more flexibility for renaming files in a command-line environment. Using PowerShell, you can pipe the output of one command – known as a “commandlet” in PowerShell terms — to another command, just like you can on Linux and other UNIX-like systems.
PowerShell 为在命令行环境中重命名文件提供了更大的灵活性。使用 PowerShell,您可以将一个命令(在 PowerShell 术语中称为“commandlet”)的输出通过管道传输到另一个命令,就像在 Linux 和其他类 UNIX 系统上一样。
First of all, open Powershell ISE and then navigate to the directory (folder) that has the files and folders you'd like to rename by using this command:
首先,打开 Powershell ISE,然后使用以下命令导航到包含要重命名的文件和文件夹的目录(文件夹):
cd "C:\your\directory\"
The two important commands you'll need are Dir, which lists the files in the current directory, and Rename-Item, which renames an item (a file, in this case). Pipe the output of Dir to Rename-Item and you're in business.
您需要的两个重要命令是 Dir,它列出当前目录中的文件,以及 Rename-Item,它重命名一个项目(在本例中是一个文件)。将 Dir 的输出通过管道传输到 Rename-Item,然后您就可以开展业务了。
After you launch PowerShell ISE, use the cd command to enter the directory containing your files. You should put the files in their own directory so you don't accidentally rename other files.
启动 PowerShell ISE 后,使用 cd 命令进入包含文件的目录。您应该将这些文件放在它们自己的目录中,以免意外重命名其他文件。
For example, let's say we don't want the dot character in our file names – we'd rather have an underscore instead.
例如,假设我们不想在文件名中使用点字符——我们宁愿使用下划线。
The following command lists the files in the current directory and pipes the list to Rename-Item. Rename-Item replaces each dot character with an underscore.
以下命令列出当前目录中的文件并将该列表通过管道传送到 Rename-Item。Rename-Item 用下划线替换每个点字符。
Dir | Rename-Item –NewName { $_.name –replace ".","_" }
Consult Microsoft's documentation on the Rename-Item commandletif you want help performing other, more advanced operations.
如果您需要帮助执行其他更高级的操作,请参阅 Microsoft 的 Rename-Item commandlet 文档。
回答by Gabriel
Actually this should work :
其实这应该工作:
Dir | Rename-Item –NewName { $_.Name.Replace(".","_") }
回答by mah
There isn't a windows command to do this. You should consider writing a script of some sort that obtains a directory listing and enumerates through each entry: changes the dot to an underscore, and calls the windows rename command appropriately.
没有 Windows 命令可以执行此操作。您应该考虑编写某种脚本来获取目录列表并枚举每个条目:将点更改为下划线,并适当地调用 windows 重命名命令。