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

发布于 2024-09-17 07:14:10 字数 45 浏览 2 评论 0原文

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

In a Windows command prompt, how can I rename all the files to lower case and remove all spaces?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

洛阳烟雨空心柳 2024-09-24 07:14:10

制作一个批处理文件

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ( ' dir /b /a-d *.* ') do (
set name="%%i"
set newname=!name: =!
rename "%%i" !newname!
)

注意:在测试目录下运行,看看是否有预期的结果。我还没有测试过。

编辑:忘记说这只会删除空格。

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.

幽蝶幻影 2024-09-24 07:14:10

我使用此批处理文件将所有文件夹和子文件夹重命名为小写名称:

@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

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
为人所爱 2024-09-24 07:14:10

要制作“小写”和“删除空格”的技巧......

在给定的解决方案中,在“dir”语句中,还使用“/l”

dir 中的 /L 语句强制将文件名中的文件名小写
结果。

正如“Windows-RENAME”命令,如果您使用“相同”的文件名,它会提示从大写转换为小写。

ren XPTO.TXT xpto.txt

结果总是: XPTO.TXT

为了“绕过”这个,我们使用短暂的技术:
将 old 移至 temp,然后 ->将 temp 移至 new

那么解决方案是:

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

To make the trick of "lowercase" and "remove spaces" ...

In the given solution, in the 'dir' statement, use also "/l"

The /L statement in dir forces to lowercase the filenames in the
result.

As "Windows-RENAME" command, if you use the "same" filename, it will note convert from uppercase to lowercase.

ren XPTO.TXT xpto.txt

The result will always be : 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!
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文