简体   繁体   English

将所有文件重命名为小写,替换空格

[英]Rename all files to lowercase, replace spaces

在Windows命令提示符下,如何将所有文件重命名为小写并删除所有空格?

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. 编辑:忘了说这只会删除空格。

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

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 为了“绕过”这个,我们使用短暂的技术:将旧的移动到临时,然后 - >将temp移动到新的

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!
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM