windows 将所有文件重命名为小写,替换空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3632272/
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
Rename all files to lowercase, replace spaces
提问by Ian Vink
In a Windows command prompt, how can I rename all the files to lower case and remove all spaces?
在 Windows 命令提示符下,如何将所有文件重命名为小写并删除所有空格?
回答by AMIT
Make a batch file
制作批处理文件
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ( ' dir /b /a-d *.* ') do (
set name="%%i"
set newname=!name: =!
rename "%%i" !newname!
)
NOTE: Run under a test directory and see if you have the expected result. I have not tested it.
注意:在测试目录下运行,看看是否有预期的结果。我没有测试过。
EDIT: Forgot to say this will only remove the spaces.
编辑:忘了说这只会删除空格。
回答by neutron80k
I used this batch file to rename all folders and subfolders to lowercase names:
我使用此批处理文件将所有文件夹和子文件夹重命名为小写名称:
@ECHO OFF
CALL:GETDIRS
:GETDIRS
FOR /F "delims=" %%s IN ('DIR /B /L /AD') DO (
RENAME "%%s" "%%s"
CD "%%s"
CALL:GETDIRS
CD ..
)
GOTO:EOF
回答by AOBR
To make the trick of "lowercase" and "remove spaces" ...
为了制作“小写”和“删除空格”的技巧......
In the given solution, in the 'dir' statement, use also "/l"
在给定的解决方案中,在“dir”语句中,也使用“/l”
The /L statement in dir forces to lowercase the filenames in the result.
dir 中的 /L 语句强制将结果中的文件名小写。
As "Windows-RENAME" command, if you use the "same" filename, it will note convert from uppercase to lowercase.
作为“Windows-RENAME”命令,如果您使用“相同”的文件名,它会注意从大写转换为小写。
ren XPTO.TXT xpto.txt
The result will always be : XPTO.TXT
结果总是:XPTO.TXT
To 'bypass' this, we use the ephemeral technique: move old to temp, then -> move temp to new
为了“绕过”这一点,我们使用临时技术:将旧移动到临时,然后 -> 将临时移动到新
Then the solution would be:
那么解决方案是:
@echo off
if exist temporaryfilenametorename del temporaryfilenametorename /f/q
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir *.csv /l /b /a-d') do (
set name="%%i"
set newname=!name: =!
rename "%%i" temporaryfilenametorename
rename temporaryfilenametorename !newname!
)