Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Swanzey, New Hampshire, USA
    Posts
    1,707
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with .bat file

    Recently, thru a referral on another thread, I came across the following .bat file that deletes the contents of the C:Windows/Temp folder. Unfortunately, it also deletes the folder itself along with all the sub-folders. Here it is:

    deltree /y c:windowstemp
    del c:windowstempor~1*.zip
    del c:windowstempor~1*.exe
    del c:windowstempor~1*.gif
    del c:windowstempor~1*.jpg
    del c:windowstempor~1*.png
    del c:windowstempor~1*.bmp

    Admittedly, I know virtually nothing about DOS or .bat files. hehe.. So, what I would like to know is first, is the deletion of the "Temp" folder itself a bad thing? (I am thinking of automating this .bat file to run daily at night)

    Secondly, if it is a bad thing, can someone share a command(s) to add to this existing .bat file that would leave the folders, and just delete the contents?

    Thanks,

    Pilgrim
    Jeff
    simul iustus et peccator

  2. #2
    jmatt
    Guest

    Re: Need help with .bat file

    Temp can sometimes house files you still need , so you are quite right wanting to keep it . To get it back , right click on a empty space on the desktop , select new folder , right click on it & name it Temp . Now drag it onto Windows in Explorer .
    Experiment with the batch file , maybe taking temp out of the 1st line is the answer .
    I use EasyCleaner from http://www.saunalahti.fi/tonihele
    Don't use Duplicate files unless you really know what your doing . John .

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need help with .bat file

    You could substitute this line instead of the current DELTREE:

    ECHO Y|DEL C:WINDOWSTEMP*.* to force a deletion of all files in the directory without wiping out the folder, and answering yes to the prompt that would normally appear.

    Alrenately, you could also add:
    CD C:WINDOWS
    C:
    MD TEMP

    immediately after the DELTREE - clunkier but also workable.
    -Mark

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need help with .bat file

    One thing that you can do is to replace the DELTREE command with the following command:

    ECHO Y|DEL C:WINDOWSTEMP*.*

    This will delete the contents of the temp directory without deleting the directory itself. Unfortunately, this has one negative side affect, it will not delete any subdirectories that were created in the temp directory. This could leave a lot of junk lying around.

    A second thing that you can do is to create a new temp directory after it is deleted bay adding this command after the DELTREE command:

    MD C:WINDOWSTEMP

    There is also one negative to this approach if the batch file is run while there are any files in the temp directory that are open. If there are files in the temp directory that are open when the batch file us run, then DELTREE will not be able to delete those files, and therefore will not be able to delete the directory. That means that you will get several error messages when the batch file runs. If you don't mind seeing those messages, then there is no harm done. However, there is one other possibility that might cause you a problem with this approach. If DELTREE is able to delete the directory, and if a Windows program attempts to create a new file in the temp directory before it gets recreated, that will fail. What will happen then depends on how the program trying to create the file is programmed to handle the error. This is not very likely, but it could happen.
    Legare Coleman

Posting Permissions

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