{"id":1065,"date":"2014-07-03T11:59:00","date_gmt":"2014-07-03T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/07\/03\/powertip-looking-for-folders-and-files-in-powershell\/"},"modified":"2014-07-03T11:59:00","modified_gmt":"2014-07-03T11:59:00","slug":"powertip-looking-for-folders-and-files-in-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-looking-for-folders-and-files-in-powershell\/","title":{"rendered":"PowerTip: Looking for Folders and Files in PowerShell"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Learn about looking for folders and files in Windows PowerShell.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;Why does this command show me folders instead of files?<\/p>\n<p style=\"margin-left:120px\">Dir | Where PSIsContainer -eq False<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;In Windows PowerShell, use the automatic variables&nbsp;<b>$True<\/b>&nbsp;and&nbsp;<b>$False<\/b>&nbsp;to refer to Boolean values<br \/><span style=\"font-size:12px\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; instead of the string&nbsp;<\/span><b style=\"font-size:12px\">True<\/b><span style=\"font-size:12px\">&nbsp;and&nbsp;<\/span><b style=\"font-size:12px\">False<\/b><span style=\"font-size:12px\">. To perform the comparison, Windows PowerShell converts<br \/><\/span><span style=\"font-size:12px\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the object on the right into the same type as on the left, so the string <strong>False<\/strong> is evaluated as a Boolean <strong>True<\/strong>.<\/span><\/p>\n<p style=\"margin-left:60px\">In this case, you are converting a string into a Boolean value, so if the string has characters in it, it will <br \/>become a <strong>True<\/strong>. Only an empty string becomes a <strong>False<\/strong>. This is why your sample code gives you folders <br \/>instead of files. Try it like this and you will be a lot happier with the results:<\/p>\n<p style=\"margin-left:120px\">Dir | Where PSIsContainer -EQ $False<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn about looking for folders and files in Windows PowerShell. &nbsp;Why does this command show me folders instead of files? Dir | Where PSIsContainer -eq False &nbsp;In Windows PowerShell, use the automatic variables&nbsp;$True&nbsp;and&nbsp;$False&nbsp;to refer to Boolean values&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; instead of the string&nbsp;True&nbsp;and&nbsp;False. To perform the comparison, Windows PowerShell converts&nbsp; &nbsp; &nbsp; [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[317,56,356,3,45],"class_list":["post-1065","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-gary-siepser","tag-guest-blogger","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn about looking for folders and files in Windows PowerShell. &nbsp;Why does this command show me folders instead of files? Dir | Where PSIsContainer -eq False &nbsp;In Windows PowerShell, use the automatic variables&nbsp;$True&nbsp;and&nbsp;$False&nbsp;to refer to Boolean values&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; instead of the string&nbsp;True&nbsp;and&nbsp;False. To perform the comparison, Windows PowerShell converts&nbsp; &nbsp; &nbsp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1065"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1065\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}