herewasplato Posted April 29, 2008 Posted April 29, 2008 MsCreatoR said: ...I get all three results the same: C:\DOCUME~1\User\LOCALS~1\TempAs do I. [size="1"][font="Arial"].[u].[/u][/font][/size]
keypuncher Posted April 29, 2008 Author Posted April 29, 2008 (edited) MsCreatoR Quote P.SI just trying to understand, what is the difference where the Temp directory will be kept, what is the purpose of all this?I want to have the program do some file manipulations, in each of the directories, independant of each other, on the target systems.Therefore I need to have it locate (identify) the aforementioned directories so I can point it to the correct place to continue with the other functions.As we have seen this location can vary on different systems.But I do need to work with BOTH directories. Individually would be best.Also I do not want to just find all "Temp" directories in a system as there may be others that I do not want to effect. Edited April 29, 2008 by keypuncher
GEOSoft Posted April 29, 2008 Posted April 29, 2008 (edited) What happens when you try @HomeDrive & "\Temp". That is the other common location for a Temp folder. If that's a no go then StringRight(@ScriptDir, 2) & "\Temp" EDIT: Actually I may have just found what you are looking for. There are two registry values that you can check. The settings are user specific $Tmp = RegRead("HKEY_CURRENT_USER\Environment", "Temp") or $Tmp = RefRead("HKEY_CURRENT_USER\Environment", "Tmp") See which of those actually matches the folder you are looking for. Edited April 29, 2008 by GEOSoft George Reveal hidden contents 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!"
keypuncher Posted April 29, 2008 Author Posted April 29, 2008 Quote name='GEOSoft' date='Apr 29 2008, 10:34 AM' post='513714'] What happens when you try @HomeDrive & "\Temp". That is the other common location for a Temp folder. That did not work Quote EDIT: Actually I may have just found what you are looking for. There are two registry values that you can check. The settings are user specific $Tmp = RegRead("HKEY_CURRENT_USER\Environment", "Temp") or $Tmp = RefRead("HKEY_CURRENT_USER\Environment", "Tmp") See which of those actually matches the folder you are looking for. These do point to the correct directory. Now I just have to try to use the resulting location in the rest of the script. An example, just to delete the files in %Temp%, altered to test this. does not work. $Tmp = RegRead("HKEY_CURRENT_USER\Environment", "Temp") $handle_search = FileFindFirstFile($Tmp & '\*.*') If $handle_search <> -1 Then $folder = FileFindNextFile($handle_search) If Not @error Then Filedelete($Tmp & '\' & $folder & '\*.*') EndIf FileClose($handle_search)
GEOSoft Posted April 29, 2008 Posted April 29, 2008 (edited) $Tmp = RegRead("HKEY_CURRENT_USER\Environment", "Temp") If StringRight($Tmp <> "\" Then $Tmp &= "\" $handle_search = FileFindFirstFile($Tmp & '*.*') If $handle_search <> -1 Then $folder = FileFindNextFile($handle_search) While 1 If @error Then ExitLoop Filedelete($Tmp & $folder) Wend EndIf FileClose($handle_search) If you want to also delete any folders in that dir then use $Tmp = RegRead("HKEY_CURRENT_USER\Environment", "Temp") If StringRight($Tmp <> "\" Then $Tmp &= "\" $handle_search = FileFindFirstFile($Tmp & '*.*') If $handle_search <> -1 Then $folder = FileFindNextFile($handle_search) While 1 If @error Then ExitLoop If StringInStr(FileGetAttrib($Folder), "D") Then DirRemove($Tmp & $Folder, 1) Continueloop EndIf Filedelete($Tmp & $folder) Wend EndIf FileClose($handle_search) EDIT: BTW If you want to remove everything in that folder then here is the easy way $Tmp = RegRead("HKEY_CURRENT_USER\Environment", "Temp") If FileExists($Tmp) Then If DirRemove($Tmp, 1) Then DirCreate($Tmp) EndIf Edited April 29, 2008 by GEOSoft George Reveal hidden contents 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!"
herewasplato Posted April 29, 2008 Posted April 29, 2008 @keypuncher, herewasplato said: Please do not take this as condescending,...It was not my intent to offend by using your words - I just liked them.It looks like you are on your way to solving your problem. If I ever come across a system that does not correctly report the user temp folder using @TempDir or EnvGet("TEMP") - I'll troubleshoot it then.It would still be nice to know how you got a wrong reading from @TempDir or EnvGet("TEMP")... but we may never know. [size="1"][font="Arial"].[u].[/u][/font][/size]
keypuncher Posted April 29, 2008 Author Posted April 29, 2008 Geosoft I like your short and direct method. as... Quote EDIT: BTW If you want to remove everything in that folder then here is the easy way $Tmp = RegRead("HKEY_CURRENT_USER\Environment", "Temp") If FileExists($Tmp) Then If DirRemove($Tmp, 1) Then DirCreate($Tmp) EndIf I just tried that exact method and it did not work. Yes on this system the run commands %Temp% point to the same location as the run command of %USERPROFILES% then \local Settings\Temp which is the same reference as the key in registry HKEY_CURRENT_USER\Environment Temp which in turn is one of the Temp directories I am tryingto deal with. However the test files do not change. I'm screwing it up somehow, but hitting my head against the wall on this as it should be very simple. Just not working.
GEOSoft Posted April 29, 2008 Posted April 29, 2008 keypuncher said: GeosoftI like your short and direct method. as...I just tried that exact method and it did not work.Yes on this system the run commands %Temp% point to the same location as the run command of %USERPROFILES% then \local Settings\Temp which is the same reference as the key in registry HKEY_CURRENT_USER\Environment Tempwhich in turn is one of the Temp directories I am tryingto deal with. However the test files do not change.I'm screwing it up somehow, but hitting my head against the wall on this as it should be very simple. Just not working.What happens when you add this under the regreadIf NOT StringRight($Tmp, 1) = "\" Then $Tmp &= "\"You could also follow the above line with MsgBox(0, "TEST", $Tmp) to check the path.Also remember that DirRemove will not work if any of the files in the folder are in use and FileDelete will fail for the same reason. George Reveal hidden contents 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!"
GEOSoft Posted April 29, 2008 Posted April 29, 2008 I just thought of something else. IIRC if a folder is set in the environment it will become a "System" folder and you may not be able to delete it. Then you would have to use the other method I posted. George Reveal hidden contents 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!"
keypuncher Posted April 29, 2008 Author Posted April 29, 2008 GEOSoft said: I just thought of something else. IIRC if a folder is set in the environment it will become a "System" folder and you may not be able to delete it. Then you would have to use the other method I posted.Now it has gotten really strangePrior to this thread I started, I had it written to where the program would delete all the files in:1) Windows\Temp directory 2) (USERPROFILE)\Local Settings\Temp directory3) Windows\Prefetchit tested out so far. It deleted all the files without a glitch EXCEPT the ones in the "(USERPROFILE)\Local Settings\Temp directory" This i could not get correct.Now for some reason after trying many of the scripts posted here in trying to help me solve the problem, it will not delete any of the files at all.I had kept a copy of the original, unaltered script. When i run it now the files are not deleted.Yet the directories are still located in the same place.files are not read onlyNow I do not know what I messed up but it gets BETTER each time (BETTER to be in interpreted as FUBAR)could it be that some ofthe code i ran off of here changed the variables in the registry so the files are being hooked somehow? I do noot see the changes in the registry. The keys that should have been affected do not appear altered.any ideas?
Moderators SmOke_N Posted April 29, 2008 Moderators Posted April 29, 2008 (edited) keypuncher said: Now it has gotten really strangePrior to this thread I started, I had it written to where the program would delete all the files in:1) Windows\Temp directory 2) (USERPROFILE)\Local Settings\Temp directory3) Windows\Prefetchit tested out so far. It deleted all the files without a glitch EXCEPT the ones in the "(USERPROFILE)\Local Settings\Temp directory" This i could not get correct.Now for some reason after trying many of the scripts posted here in trying to help me solve the problem, it will not delete any of the files at all.I had kept a copy of the original, unaltered script. When i run it now the files are not deleted.Yet the directories are still located in the same place.files are not read onlyNow I do not know what I messed up but it gets BETTER each time (BETTER to be in interpreted as FUBAR)could it be that some ofthe code i ran off of here changed the variables in the registry so the files are being hooked somehow? I do noot see the changes in the registry. The keys that should have been affected do not appear altered.any ideas?I am almost afraid to ask this question seeing that you think it's ok to delete every file in the temp* directories... but didn't you have enough common sense to read any of the code you used, to see what it does, before you tried it? Edited April 29, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
keypuncher Posted April 29, 2008 Author Posted April 29, 2008 SmOke_N said: I am almost afraid to ask this question seeing that you think it's ok to delete every file in the temp* directories... but didn't you have enough common sense to read any of the code you used, to see what it does, before you tried it?First: There is no problem deleting all the files in the Temp directories. These files are temporary and not required. Any needed files by the system or applications will be replaced when the appplications creating them restarts.Second : I did look at the codes being offered. Where I quickly understood but disagreed I still tried the code as I am not concieted and beleive there are many on here who know far more then IAs to those that I did not readily understand exactly what the code was calling for... I still tried them for the same reason as stated above and also as to the people on this forum trying to be of help and support to me and others, I trust they are trying to be helpful and would not intentionaly do anything malicious.It is not "common sense" issue, it is a trust of peoples integrity.
GEOSoft Posted April 30, 2008 Posted April 30, 2008 Try rebooting the system. I've seen that happen when multiple copies of a script have been run and one or more did not close properly. George Reveal hidden contents 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!"
MHz Posted April 30, 2008 Posted April 30, 2008 (edited) keypuncher said: First: There is no problem deleting all the files in the Temp directories. These files are temporary and not required. Any needed files by the system or applications will be replaced when the appplications creating them restarts.So long as running applications are closed, then I can agree with that. Quote It is not "common sense" issue, it is a trust of peoples integrity.I appreciate your integrity but I am not sure of your ability to do it safely so I will try to help. Here is some commented code which may help you. expandcollapse popup; expand environmental variables found within strings Opt('ExpandEnvStrings', True) ; empty users temp folder _FileMassDelete(@TempDir) ; empty systems temp folder $path = RegRead('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'TEMP') If Not @error And FileExists($path) Then _FileMassDelete($path) EndIf ; empty systems prefetch If FileExists(@WindowsDir & '\Prefetch') Then _FileMassDelete(@WindowsDir & '\Prefetch') EndIf Func _FileMassDelete($path) Local $file_found, $file_fullpath, $handle_search ; get a search handle $handle_search = FileFindFirstFile($path & '\*') ; check the handle is valid If $handle_search <> -1 Then ; loop through the file search While 1 ; get the next file $file_found = FileFindNextFile($handle_search) If @error Then ExitLoop $file_fullpath = $path & '\' & $file_found ; if a directory, use DirRemove, else FileDelete If StringInStr(FileGetAttrib($file_fullpath), 'D') Then ConsoleWrite('DirRemove: ' & $file_fullpath & @CRLF) ;~ DirRemove($file_fullpath, 1) Else ConsoleWrite('FileDelete: ' & $file_fullpath & @CRLF) ;~ FileDelete($file_fullpath) EndIf WEnd FileClose($handle_search) EndIf EndFunc You can uncommented the FileDelete() and DirRemove() if satisfied after testing. I hope it is useful for you. Some things I will mention: Just because you can open the folder "temp", or any other folder in the %PATH% using the Run box, does not mean that those are the locations for normal usage. The environmental variables give the paths to be used and that is what the AutoIt macros will contain. If %TMP% <> %TEMP% then it has been IMO poorly modified. If %WINDIR% <> %SYSTEMROOT% then it has been IMO poorly modified. %TMP% and %WINDIR% are kept for backward compatibility with older OSes. Vista has even more of a double up of environmental variables that should also marry up. EnvGet("TEMP") should normally be the same as %TEMP%, %TMP% and @TempDir unless you previously used EnvSet("TEMP", "Some Other Path") which can affect %TEMP% (and EnvGet("TEMP")). Edit: Added FileClose() for the search handle. Edited April 30, 2008 by MHz
AdmiralAlkex Posted April 30, 2008 Posted April 30, 2008 This may be a little bit off topic but why would you want to empty your prefetch directory?? That would only slow down your computer.... .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
GEOSoft Posted April 30, 2008 Posted April 30, 2008 MHz said: If %TMP% <> %TEMP% then it has been IMO poorly modified. True, but it is often set by software during an installation. George Reveal hidden contents 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!"
MHz Posted April 30, 2008 Posted April 30, 2008 (edited) GEOSoft said: True, but it is often set by software during an installation.None that I an aware of.Anyone doing this then alert me as I will not touch anything that they make. I hope you understand. Edited April 30, 2008 by MHz
jvnorris Posted April 30, 2008 Posted April 30, 2008 (edited) From the looks of it you are doing something similar to me. I wrote a cleaner based on multiple users on a sigle machine. expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #include <FileListToArray3.au3> #include <File.au3> #include <Array.au3> ; ; AutoIt Version: 3.0 ; Language: English ; Platform: WinXP ; Author: James V Norris II ; ; Script Function: ; Cleans WIndows XP Machines of Variuse Junk Files to include IE Temp files in users directories ; Designed for Admin and Managment use only, Very useful to help keep clutter down in environments where ; there are multiple users on the same machine ; ;Declare Variables used globally $BaseFolder = "C:\Documents and Settings\" ;$s_Exclude = "" ;List files for selection $UserDirectories = _FileListToArray3($BaseFolder, "*", 2, 0, 0, "Administrator|All Users|Default User|LocalService|NetworkService"); Build the list of users from the docs and settings folder _ArrayDelete($UserDirectories, 0); Remove the number of folders from the array For $i = 0 To UBound($UserDirectories) - 1 $DelDir = "C:\Documents and Settings\" & $UserDirectories[$i] & "\Local Settings\Temporary Internet Files\" $deathList = _FileListToArray3($DelDir, "*.*", 2, 0, 0) For $j = 0 To UBound($deathList) - 1 DirRemove("C:\Documents and Settings\" & $UserDirectories[$i] & "\Local Settings\Temporary Internet Files\" & $deathList[$j], 1) DirRemove("C:\Documents and Settings\" & $UserDirectories[$i] & "\Local Settings\Temp\", 1) Next Next #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning MsgBox(48,"Cleaning Completed","You Clean-up of tempfiles is completed Press OK to Exit") #EndRegion --- CodeWizard generated code End --- Sleep(250) Exit I'm not sure if you can decipher this but this is how I cleared out my temp folders. Remeber this is based on multiple users on the same machine. I hard code as much as possible my directory settings. Ths is not all inclusive but shows how I build my dirstructures for cleaning up files. I avoid macros in directory structure becasue everymachine is a little different. You may just want to hard code your basedir and build off of that. THose core folders should not be deleted and sometimes you will run into issues if there is anything there that it cannot delete. those are the only issues I have. and this is only going by a previouse post where you were trying to delete things from that section. Edited April 30, 2008 by jvnorris
keypuncher Posted April 30, 2008 Author Posted April 30, 2008 Quote name='jvnorris' date='Apr 30 2008, 05:34 AM' post='514158'] From the looks of it you are doing something similar to me. I wrote a cleaner based on multiple users on a sigle machine I'm not sure if you can decipher this but this is how I cleared out my temp folders. Remeber this is based on multiple users on the same machine. I hard code as much as possible my directory settings. Ths is not all inclusive but shows how I build my dirstructures for cleaning up files. I avoid macros in directory structure becasue everymachine is a little different. You may just want to hard code your basedir and build off of that. THose core folders should not be deleted and sometimes you will run into issues if there is anything there that it cannot delete. those are the only issues I have. and this is only going by a previouse post where you were trying to delete things from that section. Correct That is a bit of what I am trying to do. Yes part of the one I am trying to write is to Delete all files in the following directories Windows\Temp Documents and Settings\(Userprofilename)\local Settings\Temp Windows\Prefetch These directories I cannot hard code as I want this to be able to run on many different wndows OS based systems, and they may not have the same locations for the "Documents and Settings\(Userprofilename)\local Settings\Temp" directory. I do not want to delete the Directories mentioned here. Justthe files within. If any files are in use they normally will not be able to be deleted without an override. At this time I am not looking to override. Just delete what is not in use / locked. I have tested many times with deleting all of the mentioned with no deleterious effects. I just want to automate it for many different systems. I was trying to, for the most part, write it myself. I appreciate your willingness to share ypour code with me. I was hoping with some assistance to be able to figure out the mistakes I was making and get mine done correctly. Seperately I had been working on the cleaner for IE. It was a little tricky as to the changes in IE7 though. I would like to keep the two programs separate.
keypuncher Posted April 30, 2008 Author Posted April 30, 2008 AdmiralAlkex said: This may be a little bit off topic but why would you want to empty your prefetch directory?? That would only slow down your computer.... Depending on what software has been running. How long it has been running. Installations being performed. Hardware limitaions of system. Confuguration. Swap file settings. Other factors. Clearing the prefetch can speed up the system.
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