locked
create/rename folder uppercase RRS feed

  • Question

  • If i create a folder in Powershell with:
    New-Item D:\TEST -type directory
    The name is all lowercase.

    How can i create a folder that the name is like i wrote it?
    And how can i rename a folder "test" to "Test" or "TEST"?

    I searched Google for an hour but its all about bulk renaming.
    Monday, November 6, 2017 12:49 PM

All replies

  • What you posted above creates the directory as TEST on my machine. To rename TEST to test or Test, you first have to name it something different, then rename it again to what you want

    Rename-Item -Path D:\TEST -NewName Test1
    Rename-Item -Path D:\Test1 -NewName Test



    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''


    Monday, November 6, 2017 12:56 PM
  • Maybe just a presentation error?
    I do this from my workstation via remote desktop on my Hyper-V 2016 server.

    Name says "VMs"
    But "cd VMs" shows "VMs" and "cd vms" shows "vms"??

    Also if i open the Hyper-V Manager on my Workstation and browse with "inspect disk" the name is lowercase. But there are others that are all uppercase.

    Monday, November 6, 2017 1:32 PM
  • Ah, I see that. Yes does the same on my machine, folder name is Test, but if I cd TEST then it shows as TEST. Since folders and files on Windows are case insensitive it is going to the proper folder, so you should not have any issues.

    Unlike in Unix/Linux where you can have two files called Test and test because it is case sensitive, Windows is case insensitive so you can only have one file in a folder called Test, as test and TEST will all be the same.


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Monday, November 6, 2017 1:47 PM
  • That is purely a result of the way PowerShell sets the current path.  It sets it using the string as you typed it. The folder name will always be the exact casing you used to create it. TO prove this just look at the folder in File Explorer.

    THe same effect does not happen on CMD


    \_(ツ)_/


    • Edited by jrv Monday, November 6, 2017 2:05 PM
    Monday, November 6, 2017 2:05 PM
  • I found something like this to be ridiculously hard in powershell, renaming folders to uppercase.  I ended up invoking cmd.  You could put "write-host" in front of "cmd" to test out what strings would be run.  This thread had the most "google juice" for this topic.

    get-childtiem -recurse -directory -path "parentfolder" | 
      foreach { cmd /c ren $_.fullname $_.name.toupper() }

    • Edited by JS2010 Sunday, August 4, 2019 5:12 PM
    Sunday, August 4, 2019 5:11 PM
  • I found something like this to be ridiculously hard in powershell, renaming folders to uppercase.  I ended up invoking cmd.  You could put "write-host" in front of "cmd" to test out what strings would be run.  This thread had the most "google juice" for this topic.

    get-childtiem -recurse -directory -path "parentfolder" | 
      foreach { cmd /c ren $_.fullname $_.name.toupper() }

    Unnecessary.

    Get-ChildItem $parentFolder -recurse -Directory |
        Rename-Item -NewName {$_.name.toupper()} -WhatIf
    Simpler and much faster.


    \_(ツ)_/

    Sunday, August 4, 2019 5:29 PM
  • If you were to actually remove the -whatif, you would see how it errors out.

    Rename-Item : Source and destination path must be different.
    At line:2 char:5
    +     Rename-Item -NewName {$_.name.toupper()}
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : WriteError: (C:\Users\js\foo\foo2:String) [Rename-Item], IOException
        + FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand

    • Edited by JS2010 Sunday, August 4, 2019 5:36 PM
    Sunday, August 4, 2019 5:36 PM
  • Yes. Now we have a bug in the Net Framework that does not allow this.   We can no longer rename an item to its uppercase name or to its own name.

    Too bad.


    \_(ツ)_/

    Sunday, August 4, 2019 6:33 PM
  • Hello,

    can you tell me the meaning of: cmd /c

    I suppose that ren => rename-item

    Wednesday, December 11, 2019 1:51 PM
  • /c just runs a command with cmd.exe then exits.

    Wednesday, December 11, 2019 1:54 PM
  • what is the difference between your code and mine?

    $chemin = "C:\users\administrateur\Desktop\mon_dossier"

    $LesRepertoires = get-childitem -recurse -path $chemin -directory

    foreach ($rep in $LesRepertoires ) 

    {

    rename-item -path $rep.fullname -Newname($rep.name.Toupper()) 

    }

    Do you want to write the line (foreach { cmd /c ren $_.fullname $_.name.toupper() }) without alias?

    Wednesday, December 11, 2019 2:04 PM
  • I am using cmd.exe, not powershell.exe.  Ren is a completely different command than rename-item.  You can also write "rename".

    Wednesday, December 11, 2019 3:06 PM