xeshan Posted June 17, 2010 Share Posted June 17, 2010 Hello Gurus! I wanted to ask how to specify the user's profile when trying to delete files in a directory. For example: FileDelete ("C:\Documents and Settings\userid\Local Settings\Temporary Internet Files\*.*") What I'm trying to figure out is how to replace the 'userid' with the specific username that is logged in. Thank you so much in advance! Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 17, 2010 Share Posted June 17, 2010 @TempDir - Path to the temporary files folder. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Yashied Posted June 17, 2010 Share Posted June 17, 2010 (edited) @UserProfileDir ?Or#Include <WinAPIEx.au3> FileDelete(_WinAPI_ShellGetSpecialFolderPath($CSIDL_INTERNET_CACHE) & '\*.*')WinAPIEx.au3 Edited June 17, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
GEOSoft Posted June 17, 2010 Share Posted June 17, 2010 FileChangeDir(@UserProfileDir & "\Local Settings\Temporary Internet Files\") $sSearch = FileFindFirstFile("*.*") If $sSearch <> -1 Then While 1 $sFile = FileFindNextFile($sSearch) If @Error Then ExitLoop FileDelete($sFile) WEnd EndIf FileClose($sSearch) 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...
Yashied Posted June 17, 2010 Share Posted June 17, 2010 FileChangeDir(@UserProfileDir & "\Local Settings\Temporary Internet Files\") $sSearch = FileFindFirstFile("*.*") If $sSearch <> -1 Then While 1 $sFile = FileFindNextFile($sSearch) If @Error Then ExitLoop FileDelete($sFile) WEnd EndIf FileClose($sSearch) But why? FileDelete() supports wldcards. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
GEOSoft Posted June 17, 2010 Share Posted June 17, 2010 (edited) But why? FileDelete() supports wldcards.I'm aware of that but I've also had issues doing it that way.@YashiedI was in a hurry and didn't have time to give you details in the answer.In a folder like the internet cache there can easily be a file that can not be deleted. When you use wildcards, the first file that won't delete causes the call to error out so it doesn't move onto the next file. If that happens with the File*Find() method it will just continue the loop and move onto the next file. Edited June 17, 2010 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...
GEOSoft Posted June 17, 2010 Share Posted June 17, 2010 ;FileChangeDir(@UserProfileDir & "\Local Settings\Temporary Internet Files\") FileChangeDir(RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Cache")) $sSearch = FileFindFirstFile("*.*") If $sSearch <> -1 Then While 1 $sFile = FileFindNextFile($sSearch) If @Error Then ExitLoop FileDelete($sFile) WEnd EndIf FileClose($sSearch) Edit: I changed the FileChangeDir() line to get the path info from the registry instead. 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...
xeshan Posted June 20, 2010 Author Share Posted June 20, 2010 Thank you so much Gurus!! I used: FileChangeDir(RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Cache")) $sSearch = FileFindFirstFile("*.*") If $sSearch <> -1 Then While 1 $sFile = FileFindNextFile($sSearch) If @Error Then ExitLoop FileDelete($sFile) WEnd EndIf FileClose($sSearch) Is there a way that FileDelete can also delete the folders in the Temp folder as well? Thank you so much!! Link to comment Share on other sites More sharing options...
Mat Posted June 20, 2010 Share Posted June 20, 2010 Thank you so much Gurus!! I used: FileChangeDir(RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Cache")) $sSearch = FileFindFirstFile("*.*") If $sSearch <> -1 Then While 1 $sFile = FileFindNextFile($sSearch) If @Error Then ExitLoop FileDelete($sFile) WEnd EndIf FileClose($sSearch) Is there a way that FileDelete can also delete the folders in the Temp folder as well? Thank you so much!! Use just "*" rather than "*.*" in the FileFindFirstFile call. AutoIt Project Listing Link to comment Share on other sites More sharing options...
GEOSoft Posted June 20, 2010 Share Posted June 20, 2010 If $sSearch <> -1 Then While 1 $sFile = FileFindNextFile($sSearch) If @Error Then ExitLoop If StringInStr(FileGetAttrib($sFile), "d") Then DirRemove($sFile) ContinueLoop EndIf FileDelete($sFile) WEnd EndIf FileClose($sSearch) 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...
Trong Posted February 15, 2013 Share Posted February 15, 2013 Delete all files/folders inside it:$iReturn = _FindDelAll(@TempDir) ;~ $iReturn = _FindDelAll("C:\Temp", 1) If $iReturn = 1 Then ConsoleWrite(" Success! " & @CRLF) ElseIf $iReturn = 0 Then ConsoleWrite(" Error! " & @CRLF) Else ConsoleWrite(" The path is not valid! " & @CRLF) EndIfexpandcollapse popupFunc _FindDelAll($zSearchDir, $zRemoveSearchDir = 0) ; /*********************************************************************** * ; * ---:| Function : _FindDelAll ; * ---:| Author : Anonimajn ; ************************************************************************ * Local $zRSD = Number($zRemoveSearchDir) If Not FileExists($zSearchDir) Or Not StringInStr(FileGetAttrib($zSearchDir), "D") Then Return Number(-1) Else If $zRSD <> 1 Then If StringRight($zSearchDir, 1) <> "\" Then $zSearchDir &= "\" Dim $xSearch, $sFile $xSearch = FileFindFirstFile($zSearchDir & "*") If $xSearch <> -1 Then While 1 $sFile = FileFindNextFile($xSearch) If @error Then ExitLoop If StringInStr(FileGetAttrib($zSearchDir & $sFile), "D") Then _RemoveDir($zSearchDir & $sFile) Else _DelFile($zSearchDir & $sFile) EndIf WEnd Else FileClose($xSearch) Return Number(0) EndIf FileClose($xSearch) Return Number(1) EndIf If $zRSD = 1 Then _RemoveDir($zSearchDir) If Not FileExists($zSearchDir) Then Return Number(1) Else Return Number(0) EndIf EndIf EndIf EndFunc ;==>_FindDel Func _DelFile($sFilePath) ; /*********************************************************************** * ; * ---:| Function : _DelFile ; * ---:| Author : Anonimajn ; ************************************************************************ * If Not FileExists($sFilePath) Or StringInStr(FileGetAttrib($sFilePath), "D") Then Return Number(-1) Else FileSetAttrib($sFilePath, "-RASH") FileDelete($sFilePath) If FileExists($sFilePath) Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFilePath & '" /G EveryOne:F', '', @SW_HIDE) If FileExists($sFilePath) Then FileDelete($sFilePath) If FileExists($sFilePath) Then Return Number(0) Else Return Number(1) EndIf EndIf EndFunc ;==>_DelFile Func _RemoveDir($sFolder) ; /*********************************************************************** * ; * ---:| Function : _RemoveDir ; * ---:| Author : Anonimajn ; ************************************************************************ * If FileExists($sFolder) And StringInStr(FileGetAttrib($sFolder), "D") And StringLen($sFolder) > 3 Then FileSetAttrib($sFolder, "-RSH", 1) DirRemove($sFolder, 1) If FileExists($sFolder) Then RunWait(@ComSpec & ' /c RD /s /q "' & $sFolder & '"', "", @SW_HIDE) If FileExists($sFolder) Then RunWait(@ComSpec & ' /c Echo y|Cacls "' & $sFolder & '" /G EveryOne:F & RD /s /q "' & $sFolder & '"', '', @SW_HIDE) If FileExists($sFolder) Then DirRemove($sFolder, 1) If FileExists($sFolder) Then Return Number(0) Else Return Number(1) EndIf Else Return Number(-1) EndIf EndFunc ;==>_RemoveDir Regards, 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