gspino Posted June 8, 2006 Share Posted June 8, 2006 I'm working on a small script and need a way to use FileDelete with a way to exclude a file name or file type. For example I want to delete all files in the Temporary Internet Files folder except for index.dat Any help would be greatly appreciated. Thanks in advance. Link to comment Share on other sites More sharing options...
Valuater Posted June 8, 2006 Share Posted June 8, 2006 can you really imagine what you are asking for you can use a loop and.... how about using If Stringinstr($file, ".dat") Then ContinueLoop you could use this for any file you dont want to delete 8) Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted June 9, 2006 Share Posted June 9, 2006 yes use the findfirstfile and findnextfile examples in the help file, and then just pop in a check and if the name returned isnt what u defined then filedelete time Link to comment Share on other sites More sharing options...
CyberSlug Posted June 9, 2006 Share Posted June 9, 2006 I thought there was always a file-locking handle on index.dat that prevented deletion by ordinary means. Anyway, another possibility that might or might not work is setting the file read-only (then restoring the original read-only state): If Not StringInStr(FileGetAttrib("index.dat"), "R") Then $reset = 1 FileSetAttrib("index.dat,"+R") FileDelete(*.*) If $reset = 1 Then FileSetAttrib("index.dat","-R") Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
gspino Posted June 9, 2006 Author Share Posted June 9, 2006 I thought there was always a file-locking handle on index.dat that prevented deletion by ordinary means. Anyway, another possibility that might or might not work is setting the file read-only (then restoring the original read-only state): If Not StringInStr(FileGetAttrib("index.dat"), "R") Then $reset = 1 FileSetAttrib("index.dat,"+R") FileDelete(*.*) If $reset = 1 Then FileSetAttrib("index.dat","-R") That's correct. When FileDelete encounters a file-locked file, the process aborts and remaining files and folders are left intact. Many times there are subfolders in the temporary internet files directory and the index.dat file is not always in the same location. I'll try some of the posted suggestions. Thanks to all. Link to comment Share on other sites More sharing options...
CyberSlug Posted June 9, 2006 Share Posted June 9, 2006 Ah, I forgot about the FileDelete aborting. The following should work: FileChangeDir(@UserProfileDir & "\Local Settings\Temporary Internet Files") ;;;FileChangeDir(@WindowsDir & "\Temporary Internet Files") ;Win98 Run(@ComSpec & " /c del *.* /q", "", @SW_HIDE) Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
gspino Posted June 9, 2006 Author Share Posted June 9, 2006 Ah, I forgot about the FileDelete aborting. The following should work:FileChangeDir(@UserProfileDir & "\Local Settings\Temporary Internet Files");;;FileChangeDir(@WindowsDir & "\Temporary Internet Files") ;Win98Run(@ComSpec & " /c del *.* /q", "", @SW_HIDE)That didn't work either. I've tried all the suggestions and none worked. I even tried using ProcessClose("explorer.exe") on the line before FileDelete. This seems like such a small problem, but it's really got me stumped. There seems to be no easy solution. I may try listing the directory and subdirectories to a file then using that to delete the files indivually except for the index.dat. That seems more trouble than it's worth, but essential to the outcome. I hope this inspires someone more talented than I to write a function to preform a FileDelete that can handle wildcard exceptions also. Link to comment Share on other sites More sharing options...
CyberSlug Posted June 9, 2006 Share Posted June 9, 2006 It would seem that the "Temporary Internet Files" is a special case. Running dir from a command prompt doesn't show anything, but dir /s does.... so the temp files have the system attribute??? Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
gspino Posted June 10, 2006 Author Share Posted June 10, 2006 It would seem that the "Temporary Internet Files" is a special case. Running dir from a command prompt doesn't show anything, but dir /s does.... so the temp files have the system attribute???/s tells dir to also include subdirectoriesThis command produces a bare filelist of all files (including subdirectories):FileChangeDir(@UserProfileDir & "\Local Settings\Temporary Internet Files")Run(@ComSpec & " /c dir /b /s >>c:\junk\filelist.txt", "", @SW_HIDE)I'll try setting up a loop, read each line in sequentially, assign a variable, then delete the file IF the filename doesn't contain the string "index.dat". Seems to me it's like using an elephant gun to kill an ant. Link to comment Share on other sites More sharing options...
CyberSlug Posted June 10, 2006 Share Posted June 10, 2006 Oops, I was confusing with dir /a:s I think I've seen command line utilities for clearing the temp internet files... Or perhaps backing up index.dat, deleteting everything, and restoring index.dat would be easier Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
gspino Posted June 10, 2006 Author Share Posted June 10, 2006 Oops, I was confusing with dir /a:sI think I've seen command line utilities for clearing the temp internet files...Or perhaps backing up index.dat, deleteting everything, and restoring index.dat would be easierI think I've got it worked out. Of course the code is raw and needs some tweaking, but it seems to work nontheless. There are multiple "Temporary Internet Files" folders, including those in the local service and network service profiles, so I need to add those routines. Here's what seems to be working. Many thanks for your help. ;================================================== FileSetAttrib(@UserProfileDir & "\Local Settings\Temporary Internet Files", "-RASHNOT", 1) FileSetAttrib(@UserProfileDir & "\Local Settings\Temporary Internet Files\*.*", "-RASHNOT", 1) FileChangeDir(@UserProfileDir & "\Local Settings\Temporary Internet Files") DirCreate("c:\junk") RunWait(@ComSpec & " /c" & " dir /b /s >> c:\junk\filelist.txt", "") ;================================================== $file = FileOpen("c:\junk\filelist.txt", 0) If $file = -1 Then Exit While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If Not StringInStr($line, "index.dat") Then FileDelete($line) If Not StringInStr($line, "index.dat") Then DirRemove($line) WEnd FileClose("c:\junk\filelist.txt") FileDelete("c:\junk\filelist.txt") DirRemove("c:\junk") ;================================================== Link to comment Share on other sites More sharing options...
gspino Posted June 12, 2006 Author Share Posted June 12, 2006 (edited) Oops, I was confusing with dir /a:sI think I've seen command line utilities for clearing the temp internet files...Or perhaps backing up index.dat, deleteting everything, and restoring index.dat would be easierIt looks like I have been spending my time on a workaround rather that focus on the true problem. The issue is that the temp internet files and it's associated index file are protected. Deleting the files and leaving the locked file index.dat is fruitless - the index.dat file rebuilds the files after they're deleted. A light bulb went off when I realized the DEP is on by default in WinXp w/Sp2. As a test, I turned off DEP and a simple FileDelete worked perfectly. If I remember correctly, DEP is controled through a setting in the boot.ini file and a group policy setting. I'm going to research this a little more to see if I can create a DEP exception, delete the temp files and then restore the DEP setting.Thanks for everyone who offered help.-Glen Edited June 13, 2006 by gspino 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