{"id":67073,"date":"2006-06-20T09:09:00","date_gmt":"2006-06-20T09:09:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/06\/20\/how-can-i-retrieve-a-list-of-all-the-files-that-have-no-file-extension\/"},"modified":"2006-06-20T09:09:00","modified_gmt":"2006-06-20T09:09:00","slug":"how-can-i-retrieve-a-list-of-all-the-files-that-have-no-file-extension","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-retrieve-a-list-of-all-the-files-that-have-no-file-extension\/","title":{"rendered":"How Can I Retrieve a List of All the Files That Have No File Extension?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I retrieve a list of all the files that have no file extension?<BR><BR>&#8212; JB<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"TechNet Script Center\" border=\"0\" alt=\"TechNet Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, JB. Funny you should ask about no-hitters. Yes, it\u2019s true: the Scripting Son was robbed of a no-hitter this past Saturday. With one out in the top of the seventh (you play just seven innings in Colt League baseball), the Scripting Son had a no-hitter going. The next batter dribbled a ball down the third base line. It was clearly a foul ball; at first the batter didn\u2019t even run but just stood there and watched. Unfortunately, though, the home plate umpire didn\u2019t see it that way. He called the ball fair and, after a mad scramble, the batter managed to get safely to first. Officially, it was a base hit and, officially, the no-hitter was over.<\/P>\n<TABLE id=\"EYC\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. Uh, no, it\u2019s probably best if we don\u2019t relate the opinions of the Scripting Son regarding this call. Let\u2019s just say that he was happy the team won, and leave it at that.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>What\u2019s that? Yes, we noticed that the question said \u201cno file extension\u201d rather than \u201cno-hitter.\u201d We just assumed that was a typo. Surely no one could be thinking about <I>work<\/I> at a time like this. (The time, of course, being baseball season.)<\/P>\n<P>On the other hand, it\u2019s theoretically possible that someone might be more interested in a scripting than they are in hearing about the pitching exploits of the Scripting Son. (Unlikely, but still possible.) Just in case JB really <I>did<\/I> mean \u201cno file extension,\u201d here\u2019s a script that will take care of that:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colFiles = objWMIService.ExecQuery _\n    (&#8220;Select * from CIM_DataFile where Extension = &#8221;&#8221;)<\/p>\n<p>For Each objFile in colFiles\n    Wscript.Echo objFile.Name\nNext\n<\/PRE>\n<P>Yes, it\u2019s very easy. (After all, we\u2019re entering the home stretch of the baseball season; we don\u2019t have <I>time<\/I> to write long and complicated scripts!) As you can see, we begin by connecting to the WMI service on the local computer. Is it possible to connect to a <I>remote<\/I> computer and find all the files that don\u2019t have file extensions? Of course it is: just assign the variable strComputer the name of the remote machine. For example, this modified line of code will cause the script to search the computer atl-fs-01 for files without file extensions (not to be confused with Doctors Without Borders, Parents Without Partners, or A Day Without Sunshine):<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-fs-01&#8221;\n<\/PRE>\n<P>After making the connection we then issue the following query:<\/P><PRE class=\"codeSample\">Set colFiles = objWMIService.ExecQuery _\n    (&#8220;Select * from CIM_DataFile where Extension = &#8221;&#8221;)\n<\/PRE>\n<P>What we\u2019re doing here is querying the CIM_DataFile class, the WMI class used for managing files. Of course, we don\u2019t want a list of <I>all<\/I> the files on the computer, just those that don\u2019t have a file extension. To do that, we simply tack on a Where clause that limits returned data to files where the <B>Extension<\/B> property is equal to nothing (that is, an empty string: \u2018\u2019). <\/P>\n<P>Our query returns a collection of all the files that don\u2019t have a file extension. To review that list we set up a For Each loop to walk through the collection, and then echo back the <B>Name<\/B> (path) for each file found there. It\u2019s that easy.<\/P>\n<TABLE id=\"EGE\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. Could we echo back other file properties besides Name? Sure; see the <A href=\"http:\/\/null\/technet\/scriptcenter\/guide\/sas_fil_overview.mspx\" target=\"_blank\"><B>Microsoft Windows 2000 Scripting Guide<\/B><\/A> for details.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Here\u2019s an equally sad story for you. Last Thursday one of our pitchers had a no-hitter after four innings. In the top of the fifth, the leadoff batter hit a ground ball right to the shortstop. Our shortstop took a little too much time, and then kind of lobbed the ball over to first. The batter beat it out for an infield single, the first &#8211; and only &#8211; hit the other team had all night. In other words, that\u2019s twice in the span of just three days that we could have &#8211; and probably should have &#8211; had no-hitters. But we ended up with nothing at all. <\/P>\n<P>Maybe we\u2019ll give our pitchers a copy of the script that finds files that don\u2019t have file extensions. <I>That<\/I> should cheer them up!<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I retrieve a list of all the files that have no file extension?&#8212; JB Hey, JB. Funny you should ask about no-hitters. Yes, it\u2019s true: the Scripting Son was robbed of a no-hitter this past Saturday. With one out in the top of the seventh (you play just seven innings [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[38,3,12,5],"class_list":["post-67073","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-files","tag-scripting-guy","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I retrieve a list of all the files that have no file extension?&#8212; JB Hey, JB. Funny you should ask about no-hitters. Yes, it\u2019s true: the Scripting Son was robbed of a no-hitter this past Saturday. With one out in the top of the seventh (you play just seven innings [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67073","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67073"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67073\/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=67073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}