Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8247521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:52:28+00:00 2026-06-07T22:52:28+00:00

I am pretty new to powershell. Need help in writing a script to count

  • 0

I am pretty new to powershell.

Need help in writing a script to count the total number of lines in a visual studio project provided I ommit (ignore) the commented lines in the code. Eg: <‘> single quote as in vb.net. Whichever line is commented i.e begins with <‘> single quote I do not need to consider in the lines count of the file.

I’ve been successful so far in writing the script for counting the number of lines in a project based on the file types(say *.vb etc). like below

(dir -include *.cs,*.xaml -recurse | select-string .).Count
  • I now need how can I ignore the line beginning with a single quote while counting?
  • Could you suggest something i can include alongwith the above code line??

Any help would be greatly appreciated!

Thanks,
Ashish

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:52:30+00:00Added an answer on June 7, 2026 at 10:52 pm

    Try

    (gc c:\file.vb | ? { !$_.startswith("'") }).count
    

    Edit after comment:

    try this:

    dir c:\myfolder -include *.cs,*.xaml,*.txt -Recurse | % { $count = (gc $_ |  ? { $_ -notmatch '^\s*$|^''|/\*|\*/' }).count; if ($count) {write-host "$_ `tcount: $count"} }
    

    this one count no empty lines, no line starting with ‘ and no lines containing /* or */.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a powershell script to deploy a number of reports to SQL Server
Am pretty new to ROR. Need help in Rails form validation. Am using rails
I am pretty new to Powershell and having trouble checking if a number in
Hi I'm still pretty new to powershell so I apologize if I ask something
I pretty new to Objective-C (and C itself) and need to consume a NSData
I'm pretty new to Powershell. I have 2 different scripts I'm running that I
I'm calling a powershell script from C#. The script is pretty small and is
I'm pretty new to powershell, so I won't be surprised at all if I'm
I'm fairly new to Powershell and have written some pretty large scripts ie a
I'm pretty familiar with PHP, Javascript, etc but I'm new to Powershell. I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.