Hi all, In certain circumstances, I prefer to bulk rename files in a given directory so all files are lowercase. I currently use the below command in CMD, which I found online, to achieve this; Code: for /r %D in (.) do @for /f "eol=: delims=" %F in ('dir /l/b/a-d "%D"') do @ren "%D\%F" "%F" The process I currently do is; - Have the command in a txt file - Open the txt file and copy the command - Go to the directory that has files I want to lowercase - Shift + Right Click and "Open Command Window Here" - Paste and execute the command I'm wondering if there would be a way I can streamline this process. Thanks.
So after doing a little more tinkering on my own, I've shorten the process somewhat. I've put the command (with double % signs) into a batch file, named it "lowercase.bat" and placed it in System32; Code: C:\Windows\System32\lowercase.bat for /r %%D in (.) do @for /f "eol=: delims=" %%F in ('dir /l/b/a-d "%%D"') do @ren "%%D\%%F" "%%F" Now, when I Shift + Right Click and "Open Command Window Here", I simple type "lowercase".
I got bored today, and after about 20 minutes of Googling, I've streamlined this process even further. Create and place Lowercase.bat into C:\Windows\System32 with the following content; Code: @ehco off for /r %%D in (.) do @for /f "eol=: delims=" %%F in ('dir /l/b/a-d "%%D"') do @ren "%%D\%%F" "%%F" exit Create and run Lowercase.reg with the following content; Code: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\Background\shell\Run Lowercase Script] @="&Run Lowercase Script" "Icon"="%SystemRoot%\\System32\\shell32.dll,71" [HKEY_CLASSES_ROOT\Directory\Background\shell\Run Lowercase Script\command] @="C:\\Windows\\System32\\Lowercase.bat \"%V\"" Now all you have to do is navigate to the directory that contains all files you want to lowercase the filenames of, right-click a blank space in explorer, and select Run Lowercase Script from the context menu. The script will than run in that directory.
Or Put this into a uppercase_to_lowercase.cmd file and run this file in this folder where You want to change file names Code: for /f "Tokens=*" %%f in ('dir /l/b/a-d') do (rename "%%f" "%%f") for /r /d %%x in (*) do ( pushd "%%x" for /f "Tokens=*" %%f in ('dir /l/b/a-d') do (rename "%%f" "%%f") popd ) or make this powershell script and run it in desired folder Code: dir | Rename-Item -NewName { $_.Name.ToLowerInvariant() }
I've been using my above solution daily for the last few years without issue. Except today was the first time I've accidently ran it in a directory where I hadn't intended to. Wasn't overly important though. So I thought I would finally get around to testing out ChatGPT (yes I know, it's taken a while), and making some changes, and here they are: Lowercase.bat Code: @echo off echo Are you sure you want to rename all files to lowercase? echo [Y] Yes echo [N] No choice /C YN /N if errorlevel 2 exit /b for /f "eol=: delims=" %%F in ('dir /l/b/a-d') do ( ren "%%F" "%%F" ) exit /b Lowercase.reg Code: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\Background\shell\Lowercase] @="Convert to Lowercase" "Icon"="%SystemRoot%\\System32\\shell32.dll,71" [HKEY_CLASSES_ROOT\Directory\Background\shell\Lowercase\command] @="cmd.exe /c C:\\Windows\\System32\\Lowercase.bat \"%V\"" Now I'm prompted before the command is executed, and a simple press of Y or N on the keyboard is required. Also changed the command itself a bit. Previously it was also looking inside subdirectories and renaming those files (which I did not realise as I was never in that situation). That no longer occurs. It will name only rename files in a base directory.