如何在文件夹的所有文件名中用下划线替换所有空格? [英] How to replace all spaces by underscores in all file names of a folder?
问题描述
我正在尝试重命名文件夹中的所有文件(所有 .exe 文件).我想用下划线替换所有空格,例如qwe qwe qwe asd.exe
到 qwe_qwe_qwe_asd.exe
.
I'm trying to rename all the files inside a folder (all .exe files). I want to replace all the spaces with underscores, e.g. qwe qwe qwe asd.exe
to qwe_qwe_qwe_asd.exe
.
我需要使用命令行来执行此操作.我尝试了很多我在互联网上甚至在这个网站上找到的可能的解决方案,但我不能让它工作.
I need to do this using the command line. I tried a lot of possible solutions I found on internet and even on this site, but I can't make it work.
我还需要在一行"/一个命令"中执行此操作,但我会接受所有有效答案.
I also need to do this in "one single line" / "one command", but I'll accept all the working answers.
推荐答案
一行一行
cmd /e:on /v:on /c "for %f in ("* *.exe") do (set "n=%~nxf" & set "n=!n: =_!" & ren "%~ff" "!n!" )"
生成一个cmd实例,启用扩展和延迟扩展,并且对于每个名字中有空格的exe文件,用下划线替换空格并用新名称重命名文件
Spawn a cmd instance, with extensions and delayed expansion enabled, and for each exe file with spaces in name, replace spaces with underscores and rename the file with the new name
这篇关于如何在文件夹的所有文件名中用下划线替换所有空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!