Powershell loop through folders, create file in each folder Powershell loop through folders, create file in each folder powershell powershell

Powershell loop through folders, create file in each folder


Try this:

Get-ChildItem -Recurse -Directory | ForEach-Object {New-Item -ItemType file -Path "$($_.FullName)" -Name "$($_.Name).txt" }

Basically, the Get-ChildItem command returns a sequence of DirectoryInfo objects. The FullName property contains the full path, whilst Name just contains the name of the leaf directory.