How to create empty files in all empty folders using PowerShell? -
i want create empty text files in subfolders empty. following piece of script list empty subfolders.
$a = get-childitem d:\test -recurse | where-object {$_.psiscontainer -eq $true} $a | where-object {$_.getfiles().count -eq 0} | select-object fullname how can iterate through output of above command , create empty text files in them?
there few many loops in answer made yourself. offer solution make empty file in directories not have files ( solution ok if have folders i'm keeping logic.)
get-childitem -recurse c:\temp | where-object {$_.psiscontainer -and ($_.getfiles().count -eq 0)} | foreach-object{[void](new-item -path $_.fullname -name "touch.txt" -itemtype file)} if $_.psiscontainer false won't bother other condition of checking files. cast output of new-item void stop output of created new files.
Comments
Post a Comment