0

I know there are similar posts, but non covers what I need. I need to rename all the files and sub folders of a given folder and make them uppercase. I found this post which is great but only does the files OR subfolders:

Rename all files in folder to uppercase with batch

I tried doing nested FOR with no joy. According to the manual, /R is suppose to recur through folders, but it is not doing anything. Tried /D /R with no luck either. So I was hoping to use something like below:

@echo off
setlocal enableDelayedExpansion

pushd C:\MyFolder

for /R /D %%f in (*) do (
   set "filename=%%~f"

   for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "filename=!filename:%%A=%%A!"
   )
    ren "%%f" "!filename!" >nul 2>&1
)
endlocal

Any ideas?

Community
  • 1
  • 1
DoctorB
  • 39
  • 1
  • 4

1 Answers1

0

Parse a static list dir /B /S * to get all files and subfolders.

Read entire for /? for %%~nxf explanation.

@echo off
setlocal enableDelayedExpansion

pushd C:\MyFolder

for /F "delims=" %%f in ('dir /B /S *') do (
   set "filename=%%~nxf"

   for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "filename=!filename:%%A=%%A!"
   )
    ren "%%~f" "!filename!" >nul 2>&1
)
popd
endlocal

Read ren /? as well:

Renames a file or files.

RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.

Note that you cannot specify a new drive or path for your destination file.
JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • this is beautiful! works like a charm ... I actually did think of printing the list but then got stuck in parsing them! – DoctorB May 16 '17 at 23:04