How do I delete certain characters or replace certain characters with other characters by some batch file execution, for filenames of all files in a Windows folder in one go, is there a DOS command for that?
相关问题
- How to Debug/Register a Permanent WMI Event Which
- What is the best way to do a search in a large fil
- Inheritance impossible in Windows Runtime Componen
- How can I do variable substitution in a here-strin
- how to get running process information in java?
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- C#调用PowerShell的问题
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- EscapeDataString having differing behaviour betwee
- Bundling the Windows Mono runtime with an applicat
- What is the correct way to declare and use a FILE
This batch file can help, but it has some limitations. The filename characters = and % cannot be replaced (going from memory here) and an ^ in the filenames might be a problem too.
In this portion
%newname: =_%
on every line in the lower block it replaces the character after:
with the character after=
so as it stands the bunch of characters are going to be replaced with an underscore.Remove the
echo
to activate the ren command as it will merely print the commands to the console window until you do.It will only process the current folder, unless you add
/s
to the DIR command portion and then it will process all folders under the current one too.To delete a certain character, remove the character from after the = sign. In
%newname:z=%
an entry like this would remove all z characters (case insensitive).Use PowerShell to do anything smarter for a DOS prompt. Here, I've shown how to batch rename all the files and directories in the current directory that contain spaces by replacing them with
_
underscores.EDIT :
Optionally, the
Where-Object
command can be used to filter out ineligible objects for the successive cmdlet (command-let). The following are some examples to illustrate the flexibility it can afford you:To skip any document files
To process only directories (pre-3.0 version)
PowerShell v3.0 introduced new
Dir
flags. You can also useDir -Directory
there.To skip any files already containing an underscore (or some other character)
I would recommend the
rename
command for this. Typeren /?
at the command line for more help.A one-liner command in Windows PowerShell to delete or rename certain characters will be as below. (here the whitespace is being replaced with underscore)
The PowerShell answers are good, but the Rename-Item command doesn't work in the same target directory unless ALL of your files have the unwanted character in them (fails if it finds duplicates).
If you're like me and had a mix of good names and bad names, try this script instead (will replace spaces with an underscore):