Jump to content

Delete TEMP


Recommended Posts

I want to delete everything in c:\temp (I've redirected the system temp to here for simplicity) but skip temp files that are still in use. FileDelete("c:\temp") seems to not do anything if it finds a file in use. The only other solution I can think of is to cycle through all the files and attempt to delete one at a time using FileNext. This is further complicated by sub-folders in Temp.

I was just hoping someone here had a magic bullet that might save me some coding - otherwise I'll get to work. :D

Edited by nauip
Link to comment
Share on other sites

I want to delete everything in c:\temp (I've redirected the system temp to here for simplicity) but skip temp files that are still in use. FileDelete("c:\temp") seems to not do anything if it finds a file in use. The only other solution I can think of is to cycle through all the files and attempt to delete one at a time using FileNext. This is further complicated by sub-folders in Temp.

I was just hoping someone here had a magic bullet that might save me some coding - otherwise I'll get to work. :D

It would be a standard recursive search. There have been lots of them posted, use the search function on the forum to find some examples.

Be careful how you test that baby though! Don't want to test it with _MyDeleteFunc("C:\*.*").

:D

Get a nice recursive function that just displays the file names, make sure that works as advertised, then you can try it with actual deletion.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You can use a line like this...

rmdir c:\Temp /s/q

...in a batch file or via the Run function in AutoIt.

It will delete all that it can and will leave the rest... at least on XP

actually this is going to work for me. Thanks!

Now if I can get out of the habit of storing crap in temp (which this is supposed to help me do) all will work out.

Link to comment
Share on other sites

You can use a line like this...

rmdir c:\Temp /s/q

...in a batch file or via the Run function in AutoIt.

It will delete all that it can and will leave the rest... at least on XP

There you go again with your simple, boring, direct solutions (that I wish I had thought of) that completely ignore the more interesting, complicated, geeky answers.

Don't forget that once you have the AutoIt hammer, every problem is a nail.

DOS command line, indeed!

Sheesh!

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

There you go again with your simple, boring, direct solutions (that I wish I had thought of) that completely ignore the more interesting, complicated, geeky answers.

Don't forget that once you have the AutoIt hammer, every problem is a nail.

DOS command line, indeed!

Sheesh!

:D

....and it will (probably) not be flagged as malware or a virus.

Malwarebytes flagged all of my AutoIt exes yesterday :-(

[but I only had 3 exe - the rest I keep as au3 files :-]

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

You can use a line like this...

rmdir c:\Temp /s/q

...in a batch file or via the Run function in AutoIt.

It will delete all that it can and will leave the rest... at least on XP

Better :

rd /s /q %temp%

Edited by Inverted
Link to comment
Share on other sites

To everyone removing their Temp directories, don't forget to re-create them so your apps don't bomb out.

Preferably with the same NTFS permissions, if applicable. :D

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

$sWorking = @WorkingDir
FileChangeDir(@TempDir)
$sSearch = FileFindFirstFile(*.*)
If $sSearch <> -1 Then

    While 1
        $sFile = FileFindNextFile($sSearch)
        If @Error Then ExitLoop
        If NOT FileDelete($sFile) Then ContinueLoop
    WEnd
FileClose($sSearch)

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

To everyone removing their Temp directories, don't forget to re-create them so your apps don't bomb out.

Preferably with the same NTFS permissions, if applicable. :D

In my case, I do happen to recreate it - but I did not used to.

...and it inherits the correct NTFS permissions.

But since this is the OS temp, XP would create it when requested. I've never had an app bomb out during the years that I did not recreate it. [Edit: I might have just been lucky?] The only reason why I started recreating it was I wanted the date/time stamp on the temp folder. Mine deletes completely each night via a scheduled task. I also delete several other junk folders like:

...Local Settings\Application Data\Microsoft\Terminal Server Client\Cache

rmdir "C:\Documents and Settings\NAMEl\Application Data\Sun\Java\Deployment\cache" /s/q

For /D %%i in ("C:\Documents and Settings\NAMEl\Application Data\Sun\Java\jre*.*") do rmdir "%%i" /s/q

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Better :

rd /s /q %temp%

To everyone removing their Temp directories, don't forget to re-create them so your apps don't bomb out.

Preferably with the same NTFS permissions, if applicable. :D

I'm not sure that's really a problem, but if so it's easy to fix:
rd /s /q %temp%\*.*

That should get the contents and not delete the parent temp dir.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...