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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:32:37+00:00 2026-05-23T05:32:37+00:00

I am writing a batch script that goes through every file in a directory

  • 0

I am writing a batch script that goes through every file in a directory looking for code files and modifies them in some way. After I finished that task I tried to run it on a large directory with about 6,000 files. About 40 minutes in the script crashed and I got lots of out of memory errors from the command prompt, running the script while looking at the task manager showed that my program was eating memory at about a rate of 1MB per loop iteration. So naturally thinking I had done something wrong I cut out all the code that I had written to isolate the problem. But then I was left with an empty file except for a for loop and the problem still persisted!

Here is what I ran on a fairly large directory like I said:

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set directory=%CD%
for /R "%directory%" %%a in (*.c *.cpp *.h *.idl) do (
    set currentDir=%%~dpa
    pushd !currentDir!
    popd
)

I have actually been able to trim it down to:

@echo off
for /R "%CD%" %%a in (*) do echo

And the problem still persists.

Is there a memory leak in the batch for loop or am I just doing something wrong?

I am running Windows XP 32bit Service Pack 2 although I have tested and confirmed the problem is still present in Service Pack 3.

  • 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-05-23T05:32:37+00:00Added an answer on May 23, 2026 at 5:32 am

    This is not so much an answer as a workaround (or rewrite). I have run your script and I see some memory consumption, which some of which is not released until the script finishes, but I do not get anything near 1 MB per iteration. (Just like @aphoria I can run the script on the root of c: without problems on XP SP3 and Vista.)

    I suggest that you closing any process not necessary for the script and run your script on one subdirectory at a time.

    If you cannot solve this in any other manner I suggest you try writing the script in Powershell.

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

Sidebar

Related Questions

I'm writing my own batch script to backup some files to an external. here's
I am writing a batch script to go through some directories doing an specific
I am writing a batch script which I wish to open a file and
I am writing a batch script intended for handling some tasks in my (and
I am writing a batch file script using Windows command and want to change
I am writing a batch file to execute some other programs. In this case
Howdy, I'm writing a batch script that will run on a Windows XP machine.
I'm writing some code that utilizes the boost filesystem library. Here is an excerpt
I need some help in writing a batch file. I have a path stored
Hey, I'm having some problems writing a batch file where I need to specify

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.