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

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -