Lowercase CMD Command Script

Discussion in 'Scripting' started by Duckz, Mar 24, 2020.

  1. Duckz

    Duckz MDL Junior Member

    Joined:
    Jan 6, 2010
    Messages:
    51
    Likes Received:
    10
    Trophy Points:
    0
    #1 Duckz, Mar 24, 2020
    Last edited: Mar 24, 2020
    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.
     
  2. Duckz

    Duckz MDL Junior Member

    Joined:
    Jan 6, 2010
    Messages:
    51
    Likes Received:
    10
    Trophy Points:
    0
    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".
     
  3. Duckz

    Duckz MDL Junior Member

    Joined:
    Jan 6, 2010
    Messages:
    51
    Likes Received:
    10
    Trophy Points:
    0
    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.
     
  4. kaljukass

    kaljukass MDL Guru

    Joined:
    Nov 26, 2012
    Messages:
    2,436
    Likes Received:
    883
    Trophy Points:
    90
    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() }