locked
Get-ChildItem to get Directories RRS feed

  • Question

  • I'm using the below code to get a list of all the directories within a path.  I need to either delete/add or change an item with the var.

    $dirs = 'C:\dir.txt'
    
    $r = Get-ChildItem -Path "C:\mydata" | ?{$_.PSIsContainer} |Select-Object Name -expandProperty Name

    This works great, however I have a folder called !Orig that I need to rename to just Orig, before sending the var out as a text file.

    Not sure how to accomplish this.

    Thanks,

    Kevin

    Wednesday, July 20, 2016 6:04 PM

Answers


  • (Get-ChildItem C:\mydata -Directory).Name | %{if($_ -eq '!Orig '){ 'Orig'}}

    \_(ツ)_/

    Wednesday, July 20, 2016 6:25 PM

All replies


  • (Get-ChildItem C:\mydata -Directory).Name | %{if($_ -eq '!Orig '){ 'Orig'}}

    \_(ツ)_/

    Wednesday, July 20, 2016 6:25 PM
  • sweet thanks
    Wednesday, July 20, 2016 6:33 PM
  • Hi Kevin, Please try this as well 

    Get-ChildItem -Path C:\mydata | ?{$_.PSIsContainer} |Select-Object Name -expandProperty Name | `

    foreach {$_.replace("!","")}


    It will remove ! mark from any file and from anywhere...

    Regards

    Kam

    Thursday, July 21, 2016 1:20 PM