sam2020
1
sorry english is not my first language i will add picture as an example to express my problem.
assume i have multiple folders. lets say
Second folder
User1
inside folder there is multiple text
inside text there is multiple line. i want to add suffix and prefix based on folder name in each line like this
how can i do this? it’s bit complicated for me. kindly help please
Follow below steps.
- Get the content of the folder user1 using Get-ChildItem cmdlet
- Foreach file do a Get-Content on the file fullname ($_.FullName) at the same time store the file's parent folder base name in a variable $parent,
- Do a "{1}/$_ {1}:{2}" -f $parent,$parent,$parent
- Do a Set-Content at the end of Foreach-Object cmdlet.
A pseudo code below
$Folder = 'path to user1 dierctory'
Get-ChildItem -Path $Folder -File | Foreach-Object -Process {
$ParentFullPath = Split-Path -Path $_.FullName -Parent
$ParentBase = Split-Path -Path $ParentFullPath -Parent
$Newcontent = Get-Content -Path $_.FullName | Foreach-Object -Process {
"{1}/$_ {1}:{2}" -f $ParentBase,$ParentBase,$ParentBase
}
$Newcontent | Out-File -FilePath $_.FullName
}