{"id":777,"date":"2010-03-29T20:35:43","date_gmt":"2010-03-29T18:35:43","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=777"},"modified":"2012-05-28T13:12:57","modified_gmt":"2012-05-28T11:12:57","slug":"source-lines-of-code-count-using-powershell","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/source-lines-of-code-count-using-powershell","title":{"rendered":"Source lines of code count using PowerShell"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2010\/03\/PowerShell.jpg\" alt=\"\" title=\"PowerShell\" width=\"137\" height=\"102\" class=\"alignleft size-full wp-image-781\" \/>Source lines of code (<strong>SLOC<\/strong>) is a software metric used to measure the size of a software program by counting the number of lines in the text of the program&#8217;s source code.<\/p>\n<p>As we all know the disadvantages of this metric, sometimes we simply want to know.<\/p>\n<p>Here&#8217;s a <strong>PowerShell script<\/strong>, that recursively searches for *.cs files and counts the lines (<strong>empty lines and comments are excluded<\/strong>)<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n(dir -include *.cs -recurse | select-string &quot;^(\\s*)\/\/&quot; -notMatch | select-string &quot;^(\\s*)$&quot; -notMatch).Count\r\n<\/pre>\n<p>Brief description of what all parts are doing:<\/p>\n<ul>\n<li>dir -include *.cs -recurse : Lists all *.cs files, you can add additional extensions using a comma.<\/li>\n<li>select-string &#8220;^(\\s*)\/\/&#8221; -notMatch : Exclude comments.<\/li>\n<li>select-string &#8220;^(\\s*)$&#8221; -notMatch : Exclude empty lines.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Source lines of code (SLOC) is a software metric used to measure the size of a software program by counting the number of lines in the text of the program&#8217;s source code. As we all know the disadvantages of this metric, sometimes we simply want to know. Here&#8217;s a PowerShell script, that recursively searches for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[44],"class_list":["post-777","post","type-post","status-publish","format-standard","hentry","category-tools","tag-powershell"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/777"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=777"}],"version-history":[{"count":2,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/777\/revisions"}],"predecessor-version":[{"id":3030,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/777\/revisions\/3030"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}