rename - Renaming all files of a particular type to lowercase batch

01
2014-07
  • user3331568

    In this link Is there a way to batch rename files to lowercase?

    there is a command given

    for /f "Tokens=*" %%f in ('dir /l/b/a-d') do (rename "%%f" "%%f")
    

    This works when i want to convert all filenames in a folder to lowercase.

    However, is there any way to convert files of only one type (eg .RMT) to lowercase?

    Thanks in advance.

  • Answers
  • Keltari

    Sure thing, just add "*.RMT" inside the dir expansion, so:

    ('dir /l/b/a-d')
    

    becomes

    ('dir /l/b/a-d *.RMT')
    

  • Related Question

    rename - Renaming a file using a batch program in Vista/7. Problem with administrator access
  • Questioner

    I have a batch file that renames a file in a folder using:

    rename filename.exe filename.bac
    

    This works good in Win XP. But in Vista/7, if the batch file is run under Program Files/ it does not rename the file unless I run it as administrator. Is there any way to bypass the UAC and use this without the need to run it as administrator?

    thanks.


  • Related Answers
  • nhinkle

    If you ever worked with linux you'll note that even when you are an administrator you don't get to do everything you want without elevation. The same concept applies to UAC. Even if you are logged in as an administrator, you run with standard user privileges by default. So no, you can't just make changes to system files (like the program files directory) - that's exactly what UAC is there to prevent.

    You can disable uac if you really want to, but this is a potential security risk.

  • nhinkle

    Modifying folders and files in the program files directory requires elevation, even if you are logged in as an administrator. There are a few potential solutions to your problem:

    • Always elevate the batch file when you run it. If it is being used as a scheduled task, you can check the box for Run this task with highest privileges.

    • Use the Windows Vista/7 Elevation powertoy script to elevate just that command

    • Change the permissions in that specific subdirectory of program files to allow normal users to rename files

      To do this, go to the directory with the file you will be renaming. Right-click on the folder and click on Properties. Go to the security tab. Click advanced and then Change Permissions. Click Add and choose the account which will be running the batch file. Grant that account the necessary permissions - probably create files and delete files at a minimum. Then click OK however many times you need to dismiss all the dialogs. The specified account will now be able to modify files in that folder without needing to elevate.

    • Disable UAC. This is not recommended, as it leaves your system vulnerable

  • Richie086

    Take a look at the elevate tool

    http://technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx

    I have used this tool to run various batch files that normally require running in an administrator prompt. It turns out that if you pass the verb "runas" to either the ShellExecute API or to its COM equivalent, the ShellExecute method of Shell.Application, the application launched will prompt for elevation This tool (which consists of the files ElevateCommand.inf, elevate.cmd, and elevate.vbs) adds an elevate command to your system. This lets you launch applications that prompt for elevation from the command line, a script, or the Run dialog. For example, the following command opens Win.ini with Notepad (after prompting for elevation):

    elevate notepad c:\Windows\Win.ini
    

    When using the elevate command with Windows Script Host (WSH), Windows PowerShell™ or other scripts, you need to specify the script host executable (such as wscript, cscript, or powershell) as the application. To run a vbs, for example, you’d use this:

    elevate wscript “C:\windows\system32\slmgr.vbs” –dli
    

    The help text explains this. Use elevate with -? or with no parameters to see the help text.

    The next irritant was that there was no "Run as Administrator" context menu option (when you right-click on the file in Explorer) for most Windows script types. The one exception was for command-shell scripts (those with .bat and .cmd file extensions). So I set out to investigate this. Many of the context menu options for file types are controlled through command keys for the "object" type in the HKEY_CLASSES_ROOT section of the Registry (see Verbs and File Associations in the sidebar for details). It turns out that if that command key is named runas, the command invoked will prompt for elevation.

    Elevate HTML Application PowerToy (ElevateHTA.inf)

    Elevate Windows PowerShell Script PowerToy (ElevatePowerShellScript.inf)

    Elevate WSH Script PowerToy (ElevateWSHScript.inf, elevate.cmd, elevate.vbs)

    These PowerToys add a Run as Administrator Explorer context menu entry for HTAs, Windows PowerShell, and Windows Script Host file types respectively. ElevateWSHScript.inf also adds a Run as Administrator with Command Prompt menu entry. (Please read the note in ElevatePowerShellScript.inf before installing it.)

    Be sure to extract the power toy into c:\Windows\System32, or if you put the tool elsewhere add the directory to you $PATH variable so you can call it inside of batch scripts easily.