batch to rename dir / sudir and files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nmareis
Posts: 2
Joined: 09 Jul 2019 05:12

batch to rename dir / sudir and files

#1 Post by nmareis » 09 Jul 2019 05:18

good morning,
i am from portugal if you dont understand anithing please tryed to contact-me.
i have this batch file...but this do not renames the directories and the subdirectories, only the files.
can anyone help me?

Code: Select all

@echo off
:again
echo Enter valid entry from the below options
SET /P OPT=Which option would you like? 1) Lower 2) Upper 3) Exit

IF %OPT%==1 GOTO :Lower
IF %OPT%==2 GOTO :Upper
IF %OPT%==3 GOTO :Exit
GOTO :again

:Lower
REM "@echo off

echo Enter the directory.
echo.
set /p "dir="

pushd "%dir%"
for /f "delims=" %%i in ('"dir /a-d/b/l 2>nul"') do ren "%%i" "%%i"
popd

exit /b"

:Upper
REM "@echo off

echo Enter the directory.
echo.
set /p "dir="

pushd "%dir%"
for /f "tokens=* delims=- " %%i in ('for /f "delims=" %%j in ^('"dir /a-d/b 2>nul"'^) do @find "" "%%j"') do ren "%%i" "%%i"
popd

exit /b"


:Exit
Exit
Top
thanks

penpen
Expert
Posts: 1685
Joined: 23 Jun 2013 06:15
Location: Germany

Re: batch to rename dir / sudir and files

#2 Post by penpen » 09 Jul 2019 08:42

nmareis wrote:but this do not renames the directories and the subdirectories
You are using the command "dir /a-d/b" whose command line argument "/a-d" excludes all directories:
So you might want to use "dir /b" instead (for all instances of "dir /a-d/b" in your source).

penpen

nmareis
Posts: 2
Joined: 09 Jul 2019 05:12

Re: batch to rename dir / sudir and files

#3 Post by nmareis » 09 Jul 2019 15:59

i tried to do this...

Code: Select all

@ECHO off
:again
echo Enter valid entry from the below options
SET /P OPT=Which option would you like? 1) Lower 2) Upper 3) Exit    

IF %OPT%==1 GOTO :Lower
IF %OPT%==2 GOTO :Upper
IF %OPT%==3 GOTO :Exit
GOTO :again

:Lower
REM "@echo off

echo Enter the directory.
echo.
set /p "dir="

pushd "%dir%"
for /f "delims=" %%i in ('"dir /b/l 2>nul"') do ren "%%i" "%%i"
popd

exit /b"

:Upper
REM "@echo off

echo Enter the directory.
echo.
set /p "dir="

pushd "%dir%"
for /f "tokens=* delims=- " %%i in ('for /f "delims=" %%j in ^('"dir /b 2>nul"'^) do @find "" "%%j"') do ren "%%i" "%%i"
popd

exit /b"


:Exit
Exit
Top
only change folders to lowercase and not to uppercase.....can you help-me?

pieh-ejdsch
Posts: 198
Joined: 04 Mar 2014 11:14
Location: germany

Re: batch to rename dir / sudir and files

#4 Post by pieh-ejdsch » 11 Jul 2019 01:14

hello nmareis,

use the error message of find.

Code: Select all


:Upper
REM "@echo off

echo.
set /p "dir=Enter the directory: "

pushd "%dir%"
for /f "delims=" %%i in (' dir /b 2>nul ') do for /f "tokens=2 delims=\" %%j in (' 2^>^&1 find "" "\%%i\.." ') do ren "%%i" "%%j"
popd

exit /b"


:Exit
Exit
Top
this only print the filename or a directoryname (does NOT search for no signs)

Phil

Post Reply