[quote quote=245580]In order for the script to search through subfolders as well you need to add the
-Recurse switch to the
Get-ChildItem command in the first line.
Name should absolutely be a known property.
What happens if you run the following commands on a known file from the Powershell prompt?
Get-ChildItem KnownFile.json (Get-ChildItem KnownFile.json).Directory (Get-ChildItem KnownFile.json).Directory | Select-Object -ExpandProperty Name
I get the name of the directory…
Currently, code looks like this
$files = Get-ChildItem -recurse -path C:\Users\path\path -filter *.json
foreach ($file in $files)
$content = Get-Content $file
if ($content -match "placeholder")
$content = $content -replace "placeholder", $file.Directory | Select-Object -ExpandProperty Name
Set-Content $file $content
My file structure goes like this
Main Folder -> Subfolder that I need the name of -> file 1 with placeholder; file 2 with placeholder; file 3 with placeholder; file 4 with placeholder;
I have multiple subfolders, but it’s only searching for .json files, even if I remove -filter, it tries to find .json files in the main folder, actually finds them, displays an error with path Main folder -> file1 with placeholder; etc. , but says that the path does not exist. Because it doesn’t exist and shell just doesn’t see the subfolder