Rename all files to lowercase, replace spaces

2019-05-30 19:19发布

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

3条回答
Lonely孤独者°
2楼-- · 2019-05-30 19:45

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
查看更多
聊天终结者
3楼-- · 2019-05-30 19:48

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!
)
查看更多
我只想做你的唯一
4楼-- · 2019-05-30 19:59

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.

查看更多
登录 后发表回答