Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch Maintence Script for Sub Directories  (Read 2515 times)

0 Members and 1 Guest are viewing this topic.

whyster

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    Batch Maintence Script for Sub Directories
    « on: March 28, 2011, 11:25:19 AM »
    Hello,
    Im fairly new to cmd scripting and I have been trying to write a script that would go through a all of the sub-directories in a specific folder and run the following script which would save the 10 most recent files and delete the rest within that sub folder.

    Code: [Select]
    for /f "skip=10 tokens=*" %%a in ('dir /a:-d /b /o:-d') do del %%a
    The issue i'm having is trying to figure out how to have this run in every single sub-directory, If anyone can point me in the right direction on how I can solve this issue I would be forever greatful, this is how my .bat file currently looks:

    Code: [Select]
    @echo off &setlocal
    set folder=C:\test\
    pushd "%folder%"

    for /f "skip=10 tokens=*" %%a in ('dir /a:-d /b /o:-d') do del %%a

    popd

    pause
    « Last Edit: March 28, 2011, 11:37:36 AM by whyster »

    whyster

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Unknown
      Re: Batch Maintence Script for Sub Directories
      « Reply #1 on: March 29, 2011, 07:21:24 AM »
      Deleteme