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

  • SEARCH
  • Home
  • 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 8832293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:29:44+00:00 2026-06-14T08:29:44+00:00

i have 300 text files in folder1 and 300 text files in folder2 below

  • 0

i have 300 text files in folder1 and 300 text files in folder2

below is a sample content of one text file

india,car,10
uk,car,20
us,car,50

i want to sum the 3rd column and write that total to same text file.
example,

for /f "tokens=3 delims=," %%a in (folder1\textfile1.txt) do set /a total+=%%a
echo %total% >folder1\textfile1.txt 

the above code will write 80 in textfile1.txt

please tell how to do the same for all the 300 text files using a batch file.

  • 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-14T08:29:45+00:00Added an answer on June 14, 2026 at 8:29 am
    @echo off
    for %%F in (
      folder1\*.txt
      folder2\*.txt
    ) do (
      set /a total=0
      for /f "usebackq tokens=3 delims=," %%a in ("%%F") do set /a total+=%%a
      echo %total% >"%%F"
    )
    

    Important points:

    1) You are replacing the content of each file (many lines) with a single line containing the total. If you want to preserve the original data and append the total to the end then you need to use >> instead:

    echo %total% >>"%%F"
    

    2) The maximum integer value that batch can compute is 2,147,483,647. The sum total must be less than or equal to that number for each file, else it will fail. If it is possible that your total can exceed that value then you will have to use some other language. Perhaps JScript, VBScript, or PowerShell.

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

Sidebar

Related Questions

I have a text file with contents as below: 1,A,100 2,A,200 3,B,150 4,B,100 5,B,250
I have some text files with the following format: 000423|东阿阿胶| 300|1|0.15000| | 000425|徐工机械| 600|1|0.15000|
I have a series of text files (one per year) which contain the answers
I have a large text file (more than 300 million records). There is a
I have many (>600) EPS files(300 KB - 1 MB) in database. In my
I have one multi-row INSERT statement (300 or so sets of values) that I
So I am writing a C# console application. I have a text file that
I have a simple Java program that reads in a text file, splits it
I have a text file that lists any possible problems. It always starts with
I have multiple html files which i saved in the assets folder. one of

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.