nauip Posted June 9, 2009 Share Posted June 9, 2009 (edited) 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. Edited June 9, 2009 by nauip Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 9, 2009 Share Posted June 9, 2009 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. 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:\*.*"). 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 More sharing options...
herewasplato Posted June 9, 2009 Share Posted June 9, 2009 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 [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
nauip Posted June 10, 2009 Author Share Posted June 10, 2009 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 XPactually 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 More sharing options...
PsaltyDS Posted June 10, 2009 Share Posted June 10, 2009 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 XPThere 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! 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 More sharing options...
herewasplato Posted June 11, 2009 Share Posted June 11, 2009 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! ....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 More sharing options...
Inverted Posted June 11, 2009 Share Posted June 11, 2009 (edited) 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 XPBetter :rd /s /q %temp% Edited June 11, 2009 by Inverted Link to comment Share on other sites More sharing options...
Skruge Posted June 11, 2009 Share Posted June 11, 2009 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. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
Inverted Posted June 11, 2009 Share Posted June 11, 2009 I've thought of that, but practically at least 1 file won't be deleted (in use). I doubt the folder will be deleted. Of course, better to check to be 100% safe. Link to comment Share on other sites More sharing options...
GEOSoft Posted June 11, 2009 Share Posted June 11, 2009 (edited) $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 June 11, 2009 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 More sharing options...
Inverted Posted June 11, 2009 Share Posted June 11, 2009 @ GEOSoft Your code has 2-3 mistakes, also FileFindFirstFile isn't recursive, so you're not really cleaning the temp folder. Link to comment Share on other sites More sharing options...
herewasplato Posted June 11, 2009 Share Posted June 11, 2009 Better :rd /s /q %temp%The OP gave a path so I used it. :-) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
herewasplato Posted June 11, 2009 Share Posted June 11, 2009 (edited) 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. 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 June 11, 2009 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2009 Share Posted June 15, 2009 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. 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. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now