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 8308851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:55:50+00:00 2026-06-08T18:55:50+00:00

Main folder Folder-Other Folder-A Folder-B (…) Folder-N Hi, I have a Main folder, a

  • 0
  • “Main” folder
    • Folder-“Other”
      • Folder-“A”
        Folder-“B”

        (…)
        Folder-“N”

Hi, I have a Main folder, a secondary folder and its several child named “folder-A, folder-B … folder-N”. Each child has txt files with lots of information in them.

I would like to read each folder (only folders A to N), collect the information within each txt and merge that information to make a Big.txt. The user would also know how many txt files were analysed and merged.

No good results so far. Any help?

@echo off
set DRV1=c:\Main\Other
set DRV2=c:\Big
cd %DRV1%
        setlocal enabledelayedexpansion
        set /a count=0 
          for %%f in (*.txt) do (
            for /f "delims= " %%a in (%%f) do ( 
            set /a count+=1 
            echo %%a >> %DRV2%\Big.txt
          )
     )
endlocal
echo There were processed %count% txt files ... 
  • 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-08T18:55:52+00:00Added an answer on June 8, 2026 at 6:55 pm

    There’s a couple of problems here:

    • First, you’re missing an iteration over the directories you wish to scan for .txt files.
    • Then you’re trying to read the files line-by-line in the inner FOR loop and that’s not working as it is – and not necessary too, because you can just use TYPE to write/append each .txt file’s contents to another file.
    • Last, you don’t need SetLocal EnableDelayedExpansion for this task – it can even cause problems if any of the .txt files have an exclamation mark ! in the filename – exclamation marks will be eaten by the delayed expansion because CMD.EXE thinks it’s part of a variable name, corrupting the filename and thus causing the contents of the file not to be included in Big.txt. By the way, I wouldn’t have known that before it hit me while fiddling around for the solution – because I actually had .txt files with an exclamation mark in the filename for testing 🙂

    Long story short, here’s what I ended up with:

    @ECHO OFF
    SET DRV1=c:\Main\Other
    SET DRV2=c:\Big
    SET /a count=0 
    :: iterate over all directories in %DRV1%
    FOR /f "tokens=*" %%F IN ( 'dir /b /a:d %DRV1%' ) DO ( 
        :: for each directory, iterate over all .txt files
        FOR %%G IN ( %DRV1%\%%F\*.txt ) DO (
            SET /a count+=1 
            TYPE %%G >> %DRV2%\Big.txt
        )
    )
    ECHO There were processed %count% txt files ... 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside my main folder, I have multiple sub-folders and each sub folder contains multiple
I have the following situation. My project has a main.scala.html file and a folder
I have folder containing several files and sub-folders such as the following: -/folder -/subfolder
Suppose I have an app that transfers files placed inside a main folder to
I've got main folder: c:\test And there I have 2 folders: Movies and Photos.
Currently I have a main folder where all of the modules I write eventually
I have a form select where by default, I need a 'main' root folder
I have directory structure like this src main resources text.txt scala hello world.scala test
Specifically, I have a folder structure that looks like the below: about (main folder)
I have a bunch of XSD files in a folder under an Empty EMF

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.