1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Recursion with Folder Heirarchy Through Batch

Discussion in 'DOS/Other' started by screamoon, Jul 20, 2006.

Thread Status:
Not open for further replies.
  1. screamoon

    screamoon Thread Starter

    Joined:
    Jul 19, 2006
    Messages:
    9
    There were two issues that I was facing. So I would go step by Step.

    ISSUE 1: suppose that I have a text file with contents as:
    1)a
    2)b
    3)c
    4)d

    Now in some folder C:\Output I have some files with extension say .1

    I want to delete all other files from that folder Output apart from the files listen in the Text file.

    That means I want a script that would leave only those files which are listed in that text file and delete all others.

    This issue got resolved with this script :


    @echo
    cd c:\output
    PAUSE
    for /f %%a in (C:\Files.txt) do attrib +h %%a
    PAUSE
    del /q c:\output\*.* /A-h
    for /f %%a in (c:\Files.txt) do attrib -h %%a



    ISSUE 2: Now what I want is that suppose in that folder output I have hierarchy of folders with names as
    a, b , c, d, e....and so on.

    Some of these folders might be empty whereas some of these might have some files or maybe another subfolder in it.


    I want to write a script so that my above script checks into all the folders and if it finds that folder empty then it comes out and looks into next folder.

    So in all all the folders get analysed and the files whose names were not there in the text file get deleted, whether those files belong to the subfolders or to the root folder. My script should analyze every folder.

    I hope I am able to make you people understand what I am trying to do.


    Please help.

    Thanking you
    scream
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/484776

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice