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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:27:43+00:00 2026-06-02T18:27:43+00:00

I have a problem with the script I wrote: @echo off e: cd folder1

  • 0

I have a problem with the script I wrote:

@echo off 
e:
cd folder1
cd logs
cd App1

for /F "skip=20 delims=" %%F in ('dir /b/o-d/a-d log11101*.*') do del "%%F"

The script works well for 1 folder. It keeps the 20 latest log files, and delete all the rest of the files starting with “log11101” in the folder (because I have other log files in these folder I do not want to delete with this script…
I want to apply this script in multiple folders, but that are all in FOLDER1, using the same “for /f “skip=20…………………………….do del “%%F” .
I tought of doing something like this since the parent folder is FOLDER1/LOGS:

@echo off 
e:
cd folder1
cd logs
cd App1

for /F "skip=20 delims=" %%F in ('dir /b/o-d/a-d log11101*.*') do del "%%F"

cd ..
cd App2

for /F "skip=20 delims=" %%F in ('dir /b/o-d/a-d log11101*.*') do del "%%F"

But it doesn’t work ! It works for 1 folder, but the other, it deletes all but 1 file, instead of keeping 20 files and deleting the rest.

Would there be a way for me to put all folders I want to target with the script, something like this and run only this script once ? :

x:/folder1/logs/app1
x:/folder1/logs/app2
x:/folder1/logs/app4

for /f "skip=20...............

Thanks

  • 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-02T18:27:44+00:00Added an answer on June 2, 2026 at 6:27 pm

    I don’t see how your 2nd code base only preserves 1 file in the 2nd folder – the 2nd folder should behave identically to the 1st. Are you sure the App2 folder had more than 1 log11101* file to begin with?

    Recommendation – insert ECHO before your DEL command and look at the results. Once the output looks correct, then remove the ECHO to make the script functional.

    It takes very little code to conveniently perform your delete action on a list of folders that reside in your root:

    @echo off
    for %%D in ("App1" "App2" "App4") do (
      cd /d "e:\folder1\logs\%%~D"
      for /f "skip=20 delims=" %%F in ('dir /b /o-d /a-d log11101*.*') do echo del "%%F"
    )
    

    If you want to perform your delete on all folders within your root:

    @echo off
    for /d %%D in ("e:\folder1\logs\*") do (
      cd /d "%%D"
      for /f "skip=20 delims=" %%F in ('dir /b /o-d /a-d log11101*.*') do echo del "%%F"
    )
    

    I’ve added the ECHO before DEL, so once everything looks good, remove ECHO to make it functional.

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

Sidebar

Related Questions

I have an interesting problem. I wrote the following perl script to recursively loop
I've got strange problem with cut I wrote script, there I have row: ...
I have wrote this little script which generates a nice random password. The problem
I have problem with c# script who change user AD password, when try change
I have a problem with following script. It generates a list of places which
I have a problem with a script and I don't know how to handle
I have a problem with this script. At first I had the <div> s
I have a problem with a bash script. I have to use the operator
I have a problem while executing a SSIS script component. To be honest I
I have a problem with running lame encoder via shell_exec script in php. And

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.