windows - Search multiple folder to check if they are empty using powershell -


i have bunch of directories

c:\ri1

c:\ri2

c:\ri3

... c:\ri21

how can check if empty? want go further script if 1 or more of them have files. if not, want exit. tried searching folder names , giving me 21 answer

$directoryinfo = get-childitem c:\ri* | measure-object $directoryinfo.count  if ($directoryinfo.count -eq 0) {      write-host "empty" }  else {     write-host "not empty" } 

when run get-childitem c:\ri* child items in c:\ , filter results items begin "ri". answer 21 since there 21 folders in c:\ starts "ri".

i suggest run through folders using foreach loop.

$folders = @("ri1", "ri2", "ri3")  foreach ($folder in $folders) {     $path = "c:\$folder"     $directoryinfo = get-childitem $path     if ($directoryinfo.count -eq 0)     {         write-host "empty"     }     else     {         write-host "not empty"     } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -