如何用文件夹的所有文件名中的下划线替换所有空格? [英] 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屋!