Batch file to find group of files.
Results 1 to 15 of 15

Thread: Batch file to find group of files.

  1. #1
    Join Date
    Nov 2001
    Location
    Melbourne,Australia
    Posts
    106

    Batch file to find group of files.

    What sort of commands would I need to use to find a group of files, then give me the option of deleting the lot at the end.
    I have made up a batch file for my cookies, recent, history, temp, tif, etc., but I was thinking of making another one which would say:

    Find all files on C drive of types .bak, .old, .gid, etc, then just give me a list at the end with a simple yes/no whether to delete the lot. A sort of simpler version of hard drive valet.
    You get to the stage where you want to rationalise how many different programs you have on your system, and some you do seem to be able to replace with a small batchfile, as some overlap quite a bit anyway.
    Would this be quite an easy task?

    ------------------
    cenz
    cenz

  2. #2
    Join Date
    Oct 1999
    Location
    Huntington Beach, CA, USA
    Posts
    3,137
    Try this with caution:

    echo off
    cls
    dir *.bak /s >filelist.txt
    dir *.old /s >>filelist.txt
    type filelist.txt |more
    choice /c:yn /n Delete files (Y)es! or (N)o!
    if errorlevel 2 goto finished
    If errorlevel 1 goto doit

    :doit
    del *.dll /s
    del *.old /s
    goto finished

    :finished
    choice /c:yn /n Delete filelist.txt (Y)es! or (N)o!
    if errorlevel 2 goto end
    If errorlevel 1 goto killit

    :killit
    del filelist.txt
    goto end

    :end


    You can change the path and files to what you want. You can keep the filelist it creates if you want.

    ------------------
    My
    Two Cents
    Dennis
    Visit Politalk

    [This message has been edited by Eeyore (edited 04-21-2002).]

  3. #3
    Join Date
    Feb 2000
    Location
    26.03°N 80.14°W
    Posts
    9,410
    I'm afraid the above won't work because unfortunately, neither the DEL or ERASE commands use a "/S" (subdirectory) parameter. (Type "DEL /?" [not the quotes] for DEL syntax).

    You might try something like this:
    Code:
    @echo off
    :CLEANUP.BAT v1.00 - Type "CLEANUP /?" (no quotes) for brief help
    :Begin
     if (%1)==(?) goto Syntax
     if (%1)==(/?) goto Syntax
     goto Search
    :Syntax
     echo.
     echo     Name: CLEANUP.BAT v1.00
     echo.
     echo  Purpose: After prompting user for Yes/No answer, deletes all "*.bak",
     echo           "*.old", "*.gid", "*.tmp" and "*.$$$" files found on drive C:.
     echo.
     echo   Syntax: cleanup [/?]
     echo.
     echo    Where: Optional "/?" will display this help screen
     echo.
     echo Requires: MORE.COM, CHOICE.COM and QBASIC.EXE somewhere in the PATH
     echo.
     goto End
    :Search
     cls
     echo CLEANUP.BAT v1.00
     echo.
     echo Searching drive C: for all "*.bak" files ...
     echo.
     dir/a-d/s/b c:\*.bak>cleanup$.lst
     echo Searching drive C: for all "*.old" files ...
     echo.
     dir/a-d/s/b c:\*.old>>cleanup$.lst
     echo Searching drive C: for all "*.gid" files ...
     echo.
     dir/a-d/s/b c:\*.gid>>cleanup$.lst
     echo Searching drive C: for all "*.tmp" files ...
     echo.
     dir/a-d/s/b c:\*.tmp>>cleanup$.lst
     echo Searching drive C: for all "*.$$$" files ...
     echo.
     dir/a-d/s/b c:\*.$$$>>cleanup$.lst
     copy cleanup$.lst+,,>nul
     if exist cleanup$.lst goto View
    :Nothing to do
     echo No files of type:
     echo.
     for %%x in (bak old gid tmp $$$) do echo *.%%x
     echo.
     echo were found.
     goto Done
    :View
     cls
     more cleanup$.lst
     echo.
     choice/c:ynv/n "Delete these files? (Y/N), (or [V]iew list again) (Y/N/V): "
     if errorlevel 3 goto View
     if errorlevel 2 goto Done
    :Delete
     echo OPEN "cleanup$.lst" FOR INPUT AS #1>cleanup$.bas
     echo OPEN "cleanup$.bat" FOR OUTPUT AS #2>>cleanup$.bas
     echo PRINT #2, "@echo on">>cleanup$.bas
     echo DO WHILE NOT EOF(1)>>cleanup$.bas
     echo   LINE INPUT #1, Rec$>>cleanup$.bas
     echo   PRINT #2, "del " + CHR$(34) + Rec$ + CHR$(34)>>cleanup$.bas
     echo LOOP>>cleanup$.bas
     echo CLOSE : SYSTEM>>cleanup$.bas
     qbasic /run cleanup$.bas
     cls
     call cleanup$.bat
    :Done
     for %%x in (lst bas bat) do if exist cleanup$.%%x del cleanup$.%%x
     echo.
     echo Processing complete. Exiting to DOS.
     echo.
    :End
    Vernon Frazee, Microsoft MVP (Windows - Shell/User)

    Defenses Up!
    Tip: When prompted for a password, give an incorrect one first. A phishing site will accept it; a legitimate one won't.


    Inside Spyware: A Guide to Finding, Removing and Preventing Online Pests


    If you don't keep up with security fixes, your computer|network won't be yours for long.

  4. #4
    Join Date
    Oct 1999
    Location
    Huntington Beach, CA, USA
    Posts
    3,137
    Darn it Vernon! I keep forgetting that I an running Norton 7.0's NDOS. I have to remember to test these things out in MS-DOS.

    You gotta admit, mine is simpler than yours.
    ------------------
    My
    Two Cents
    Dennis
    Visit Politalk

  5. #5
    Join Date
    Nov 2001
    Location
    Melbourne,Australia
    Posts
    106
    Thats pretty impressive, not only is this something I can use, but I'm trying to learn a bit more about DOS, so I will study this for a while to figure the logic involved, so in the future I can come up with more involved batch files myself.
    I really appreciate this.

    ------------------
    cenz
    cenz

  6. #6
    Join Date
    Oct 1999
    Location
    Huntington Beach, CA, USA
    Posts
    3,137
    pompeyfan that sounds dangerous. One more programer for the world to watchout for.
    ------------------
    My
    Two Cents
    Dennis
    Visit Politalk

  7. #7
    Nix's Avatar
    Nix is offline Aka: Nix*, NNiixx, Nix23
    Join Date
    May 2001
    Location
    Sydney, Australia
    Posts
    8,255
    Originally posted by Eeyore:
    Try this with caution:

    echo off
    cls
    dir *.bak /s >filelist.txt
    dir *.old /s >>filelist.txt
    type filelist.txt |more
    choice /c:yn /n Delete files (Y)es! or (N)o!
    if errorlevel 2 goto finished
    If errorlevel 1 goto doit

    :doit
    del *.dll /s
    del *.old /s
    goto finished

    :finished
    choice /c:yn /n Delete filelist.txt (Y)es! or (N)o!
    if errorlevel 2 goto end
    If errorlevel 1 goto killit

    :killit
    del filelist.txt
    goto end

    :end

    You can change the path and files to what you want. You can keep the filelist it creates if you want.
    Eyeore, lucky that Vernon pointed out your version wouldn't work.

    The highlighted command would have been a bit devastating on any system.

    Sure would have cleared out a few files.

    ------------------
    File it under X for X-perience.

  8. #8
    Join Date
    Nov 2001
    Location
    Melbourne,Australia
    Posts
    106
    Tried that batch file last night Vernon, works like a beauty, thanks again.
    I will probably expand it over time to include a few extra file types.

    ------------------
    cenz
    cenz

  9. #9
    Join Date
    Oct 1999
    Location
    Huntington Beach, CA, USA
    Posts
    3,137
    Nix, That what happens when you post in your sleep. I thought I had changed those before I posted. I use a Ramdisk to test the stuff on. So I copied a directory and it worked fine. I forgot that I was working under the NDOS command com. I have had batch files that worked fine under MS-DOS and filed under NDOS as well. Like most programs, you are looking for that program that include all the best features of all the same type programs, and it just ain't gonna happen.

    I didn't chime in right away. So I tested my creation. Glad Vernon was right on my heals when I finally did post.

    ------------------
    My
    Two Cents
    Dennis
    Visit Politalk

  10. #10
    Join Date
    Feb 2000
    Location
    26.03°N 80.14°W
    Posts
    9,410
    Eeyore> Darn it Vernon! I keep forgetting that I an running Norton 7.0's NDOS. I have to remember to test these things out in MS-DOS. You gotta admit, mine is simpler than yours.



    pompeyfan> Thats pretty impressive, not only is this something I can use, but I'm trying to learn a bit more about DOS, so I will study this for a while to figure the logic involved, so in the future I can come up with more involved batch files myself. I really appreciate this.

    You're welcome, and Thanks. If you have any questions about how something works in there, feel free to ask away.

    By the way, MS-DOS versions 5.00 through 6.22 came with a handy menu-driven "HELP" command. All of the basic DOS commands were covered with Syntax, Notes and Examples screens for most.

    Don't know exactly what Operating System you're running but try typing "HELP" (sans the quotes) at the DOS prompt. If you get a "Bad command or filename" error you probably don't have it available. (I copied it from my MS-DOS 6.22 diskettes to the \WINDOWS\COMMAND folder on all of my Windows 95+ machines).

    If you don't have HELP, you can see all of the same info beginning on this MS-DOS v6.22 Help: Command Reference page. (I converted all the HELP pages to HTML a few years ago and put them on the web).

    pompeyfan> Tried that batch file last night Vernon, works like a beauty, thanks again. I will probably expand it over time to include a few extra file types.

    You're welcome. Glad to hear it's working OK.

    Here are a few more commands that are included in my personal CLEANUP.BAT:
    Code:
    if exist %winbootdir%\tempor~1\*.* deltree /y %winbootdir%\tempor~1\
    if exist %winbootdir%\locals~1\tempor~1\*.* deltree /y %winbootdir%\locals~1\tempor~1\
    if exist %winbootdir%\cookies\*.* deltree /y %winbootdir%\cookies\
    if exist %winbootdir%\shelliconcache deltree /y %winbootdir%\shelliconcache
    if exist %winbootdir%\ff*.tmp del %winbootdir%\ff*.tmp
    for %%x in (temp tmp) do if exist %winbootdir%\%%x\*.* deltree /y %winbootdir%\%%x\
    if not (%nscache%)==() deltree /y %nscache%\
    for %%x in (%temp% %tmp%) do if exist %1\%%x\*.* deltree /y %1\%%x\
    After these run, and then most of the commands discussed above, (but in a different way*), I then finish up with the following:
    Code:
    start /w scandskw /allfixeddisks /noninteractive /silent
    defrag /all /f /detailed /noprompt
    choice /c:. /t:.,5 /n "All processing complete. Closing DOS window in 5 seconds ..."
    for %%x in (cls exit) do %%x
    The reason for the "but in a different way" is because most of my machines have more than one partition (C:, D:, E:, etc.). Hence, I need some of the commands to run against all partitions.

    Give us a holler if you have any questions ...

    [This message has been edited by Vernon Frazee (edited 04-24-2002).]
    Vernon Frazee, Microsoft MVP (Windows - Shell/User)

    Defenses Up!
    Tip: When prompted for a password, give an incorrect one first. A phishing site will accept it; a legitimate one won't.


    Inside Spyware: A Guide to Finding, Removing and Preventing Online Pests


    If you don't keep up with security fixes, your computer|network won't be yours for long.

  11. #11
    Join Date
    Nov 2001
    Location
    Melbourne,Australia
    Posts
    106
    Thanks again for the extra info, some I had already which I use in a different batch file that I run everyday to delete Cookies, tif, temp, history, recent, etc. It is as follows:

    echo Starting to Process junk.bat
    echo Looking for Smartdrv Disk Cache
    ::
    :: if the standard smartdrv disk cache is available, use it to speed things up
    if exist %winbootdir%\smartdrv.exe %winbootdir%\smartdrv.exe 2048 16
    ::
    :: The next 9 lines wipe out the main junk files
    deltree /y c:\windows\cookies\*.*
    deltree /y c:\windows\cookies\index.dat
    deltree /y c:\windows\locals~1\tempor~1\*.*
    deltree /y c:\windows\locals~1\tempor~1\Content.IE5\*.*
    deltree /y c:\windows\tempor~1\*.*
    deltree /y c:\windows\recent\*.*
    deltree /y c:\windows\history\*.*
    deltree /y c:\windows\temp\*.*
    deltree /y c:\windows\applic~1\micros~1\intern~1/userdata
    ::
    echo Erasing Icon Cache!
    ::
    :: Next line erases the icon cache, saving some resources on restart
    if exist %winbootdir%\ShellI~1\ deltree /y %winbootdir%\ShellI~1
    ::
    echo Fixing and/or Optimizing the Windows Registry!
    ::
    :: if exist %winbootdir%\command\scanreg.exe %winbootdir%\command\scanreg.exe /fix
    if exist %winbootdir%\command\scanreg.exe %winbootdir%\command\scanreg.exe /opt
    ::
    echo Done. Please reboot now.
    exit

    I don't take all credit for writing that, other people gave me ideas, and I just modified some of it to suit my system, seems to work well anyway.
    This other batch file that you gave me, I see as keeping seperate, and running about once a week, which is how often I used to run HD Valet.
    I am running 98se, and I do have the dos help file you refered to loaded on my system, which I got from the olddos.exe that comes on the windows cd.
    I also downloaded a usefull command index, but I cant remember exactly where I got it from, I think it was through the Bootdisc.com site, but I have found it excellent.
    Anyway thanks again, I will definitely be back with more questions soon.
    Cheers.

    ------------------
    cenz
    cenz

  12. #12
    Join Date
    Nov 2001
    Location
    Melbourne,Australia
    Posts
    106
    Vernon.
    The cleanup batch file finds *.gid files, but will not delete them. Is this because hidden attributes are set, and that this batch file uses delete.
    If so, I can fix this by just changing delete to deltree cant I?

    ------------------
    cenz
    cenz

  13. #13
    Join Date
    Feb 2000
    Location
    26.03°N 80.14°W
    Posts
    9,410
    Yes and yes.

    Looks like all it'll take is these three alterations:[list=1][*]Old:
    Code:
    echo Requires: MORE.COM, CHOICE.COM and QBASIC.EXE somewhere in the PATH
    New:
    Code:
    echo Requires: MORE.COM, CHOICE.COM, DELTREE.EXE and QBASIC.EXE somewhere in the PATH
    [*]Old:
    Code:
    echo PRINT #2, "@echo on">>cleanup$.bas
    Code:
    echo PRINT #2, "@echo off">>cleanup$.bas
    [*]Old:
    Code:
    echo   PRINT #2, "del " + CHR$(34) + Rec$ + CHR$(34)>>cleanup$.bas
    New:
    Code:
    echo   PRINT #2, "deltree /y " + CHR$(34) + Rec$ + CHR$(34)>>cleanup$.bas
    [/list=a]
    Vernon Frazee, Microsoft MVP (Windows - Shell/User)

    Defenses Up!
    Tip: When prompted for a password, give an incorrect one first. A phishing site will accept it; a legitimate one won't.


    Inside Spyware: A Guide to Finding, Removing and Preventing Online Pests


    If you don't keep up with security fixes, your computer|network won't be yours for long.

  14. #14
    Join Date
    Nov 2001
    Location
    Melbourne,Australia
    Posts
    106
    Thanks again Vernon, I'll try that later when I'm offline.
    I,ve added another 4 file types to the batch file, and they all work okay.
    I still haven't completely figured out the workings of the batch file yet, but I have been having a go at it, refering to my help files, I might look for more references on the net with a search, and possibly ask some questions later in a seperate thread.
    Cheers again.

    ------------------
    cenz
    cenz

  15. #15
    Join Date
    Nov 2001
    Location
    Melbourne,Australia
    Posts
    106
    Tried it last night, deletes all gid files fine now, thanks again Vernon.

    ------------------
    cenz
    cenz

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •