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

Author Topic: batch delete  (Read 2654 times)

0 Members and 1 Guest are viewing this topic.

Aug3r

    Topic Starter


    Newbie

    batch delete
    « on: March 19, 2010, 09:41:52 AM »
    I'm relatively new to BAT file programming but experienced in another language...
    With the compiler I'm using, it leaves me with 4-5 junk files that over a couple days of multiple versions..gets kinda extensive.
    So I wrote this batch file:

    @echo off
    COLOR 0A
    echo WHAT UP G33K??


    set /p file_variable="WADDAH WE DO'IN HERE ... "
    del /s "file_variable" \*.asv
    del /s "file_variable" \*.sig
    del /s "file_variable" \*.spz
    pause
    dir c:\windows

    once this is opened, I drag the folder into the window & hit enter.
    everything works ok, except for one thing...i only want the folders i specified to be cleared of such "junk files" and nothing else.
    cuz it turns out one of my "junk" files..also happens to share a similar file extension with an important windows file....which has made me have to re-install a couple times.  I removed the extension from this version (.sm2)...but if I can designate "ONLY this folder & any subfolders" i could resume the full clean...so to speak.

    any input is greatly appreciated...thank you!
    « Last Edit: March 19, 2010, 10:27:44 AM by Aug3r »

    gregflowers



      Rookie

      Thanked: 3
      Re: batch delete
      « Reply #1 on: March 19, 2010, 12:31:26 PM »
      Try this:


      Code: [Select]
      set file_variable=%1
      del /s "%file_variable%\*.asv"


      %1 is the varible that is passed to the batch file on the command line as a parameter,
      There also shoud not be spaces in the path. The variable names are enclosed in by the percent signs.

      Aug3r

        Topic Starter


        Newbie

        Re: batch delete
        « Reply #2 on: March 22, 2010, 11:59:33 AM »
        thank you!
        I will give it a shot!

        greg



          Intermediate

          Thanked: 7
          Re: batch delete
          « Reply #3 on: March 22, 2010, 09:20:20 PM »
          @echo off

          Any input is greatly appreciated...thank you!


          C:\batch>type aug.bat
          Code: [Select]
          @echo off
          echo WHAT UP G33K?
          Rem We will assume all bad files are in c:\windows
          cd  c:\windows
          dir /b *.asv *.sig *.spx
          dir /b *.asv  >  c:\temp\badfiles.txt
          dir /b *.sig >>  c:\temp\badfiles.txt
          dir /b *.spx  >>  c:\temp\badfiles.txt
          pause
          echo type  c:\temp\badfiles.txt
          type c:\temp\badfiles.txt
          pause
          for  /f "delims=" %%i in (c:\temp\badfiles.txt) do (
          echo  %%i
          del "%%i"
          )
          del c:\temp\badfiles.txt
          dir /b *.asv *.sig *.spx
          cd \

          Output:

          C:\batch>aug.bat
          WHAT UP G33K?
          bad.asv
          bad.sig
          bad.spx
          Press any key to continue . . .
          type  c:\temp\badfiles.txt
          bad.asv
          bad.sig
          bad.spx
          Press any key to continue . . .
           bad.asv
           bad.sig
           bad.spx
          File Not Found
          C:\>
          Have a Nice Day

          ghostdog74



            Specialist

            Thanked: 27
            Re: batch delete
            « Reply #4 on: March 22, 2010, 09:36:00 PM »
            @greg/bill, why go through all the trouble when you can just do
            Code: [Select]
            del *.asv *.sig *.spx