Sunday, 25 August 2013

How to lowercase file and folsder names. My solution

How to lowercase file and folsder names. My solution

This is not much of a question but a command line procedure i would like
to share. I did find various samples on the Net but none of them were
"complete" enough. Here's mine:
:
: LowerCaseFileAndFolderNames.cmd
: Aad Slingerland, 2013.
:
@echo off
if (%2)==(GO) goto for_loop
if (%1)==() (
echo\
echo Syntax: LowerCaseFileAndFolderNames foldername
echo\
echo Sample: LowerCaseFileAndFolderNames d:\util
echo\
echo Sample: LowerCaseFileAndFolderNames "d:\my data"
echo\
echo Sample: LowerCaseFileAndFolderNames .
echo\
goto end
) else (
echo\
echo Are you sure about lowercasing here and below: %1
echo\
echo Press any key to continue or Ctrl_C to abort.
pause >nul
:
set _this_drive_=%CD:~0,2%
%~d1
call :for_loop "%1"
%_this_drive_%
goto end
)
:
:for_loop
:
pushd .
echo %1
cd %1
for /f "tokens=*" %%v in ('dir * /l /b /a-d-h 2^>nul') do call
:file_not_hidden %1 "%%v"
for /f "tokens=*" %%v in ('dir * /l /b /a-dh 2^>nul') do call
:file_hidden %1 "%%v"
for /f "tokens=*" %%v in ('dir * /l /b /ad-h 2^>nul') do call
:dire_not_hidden %1 "%%v"
for /f "tokens=*" %%v in ('dir * /l /b /adh 2^>nul') do call
:dire_hidden %1 "%%v"
popd
goto end
:
:file_not_hidden
:
ren "%~2" "%~2"
goto end
:
:file_hidden
:
attrib -h "%~2"
ren "%~2" "%~2"
attrib +h "%~2"
goto end
:
:dire_not_hidden
:
call %~f0 "%~2" GO
ren "%~2" "%~2"
goto end
:
:dire_hidden
:
call %~f0 "%~2" GO
attrib -h "%~2"
ren "%~2" "%~2"
attrib +h "%~2"
goto end
:
:end
:

No comments:

Post a Comment