Get-ChildItem and subfolder pathing

Welcome Forums General PowerShell Q&A Get-ChildItem and subfolder pathing

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #5203

    Points: 0
    Rank: Member

    by ChrisL at 2012-10-17 10:26:02

    This seems like such a simple issue but I haven't been able to find anything on it. I'm using Get-ChildItem to recursively search through folder sets for particular text files, modify them, and then save the file. The problem I've been running into is that for files that are located in subfolders, instead of overwriting them, it saves them in the root folder instead. Is there a way to retreive the full path using GCI or is there a better way to do this?

    ForEach ($sFolder in $aSearchFolders) {
    If (Test-Path "$sFolder") {
    Set-Location $sFolder
    Get-ChildItem -Path $sFolder -Filter name*.xxx -Recurse | ForEach-Object { (Get-Content $_) | ForEach-Object {$_ -replace "text1", "text2"} | Set-Content $_ }

    by DonJ at 2012-10-17 10:36:18

    The File object does contain the full path. The problem is that you're using $_, which is the whole file object, so it's defaulting to the Name property. You probably want to use something like $_.FullName instead.

    by ChrisL at 2012-10-17 11:53:32

    That fixed it; thank you so much!!

The topic ‘Get-ChildItem and subfolder pathing’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort