stuka Posted September 22, 2007 Share Posted September 22, 2007 (edited) . Edited August 23, 2009 by stuka Link to comment Share on other sites More sharing options...
Blue_Drache Posted September 22, 2007 Share Posted September 22, 2007 Your question makes no sense. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
frostfel Posted September 22, 2007 Share Posted September 22, 2007 (edited) Let's say I want to delete a certain file like 'autorun.inf'. But before I delete the file, it has to match certain criterias before it is deleted.For example, if the following strings are found...open=winword.exe shellexecute=winword.exe...then only is the file deleted.Do i need an .ini file to do this? Then the user can define what criterias to delete right?"Your question makes no sense."It makes senseI made 3 .ini's in C:\inis folder 2 of them had section, key delete and it finds the ones with delete/delete and deletes thoes say you want to also delete inis with delete2/delete2 then duplicate the $read1 line and put it after the 1st if not @error and it will also delete ones with that. All the inis must be in same folderHope this helps#include <File.au3> Func DeleteIni() $FileNum = 0 $FileList = _FileListToArray("C:\inis", "*", 1) While 1 If $FileNum = $FileList[0] Then MsgBox(0, "Done", "File deletion done") Exit Else $FileNum += 1 EndIf $IniName = "C:\inis\"&$FileList[$FileNum] $Read1 = IniReadSection($IniName, "Delete") If Not @error Then FileDelete($IniName) EndIf WEnd EndFunc Edited September 22, 2007 by frostfel Link to comment Share on other sites More sharing options...
Emperor Posted September 23, 2007 Share Posted September 23, 2007 Local $File = FileOpen("autorun.inf", 0) While True Local $Line = FileReadLine($File) If @error = -1 Then ExitLoop If StringInStr($Line, "open=winword.exe") Or StringInStr($Line, "shellexecute=winword.exe") Then ; Close and delete file here EndIf WEnd I think this is what you want. Not tested by the way. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 23, 2007 Moderators Share Posted September 23, 2007 First... Your question didn't make much sense. You have to realize that help starts with a properly "detailed" question, preferably with code that you've attempted (sometimes the code makes more sense than the poster does). If it wasn't for Blue Drache at the beginning of my escapades here, I wouldn't have stayed. ***** How do you expect to read the file if it's not open to check it for the string to begin with? So, I think the Emperor was pretty much dead on. I'd only change it to reading the whole file, and take out the fileopen, because fileread already does that for you. 'psuedo code': $sReadFile = FileRead('MyFileName') If StringInStr($sReadFile, "open=winword.exe") Or StringInStr($sReadFile, "shellexecute=winword.exe") Then FileDelete('MyFileName') 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. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 23, 2007 Moderators Share Posted September 23, 2007 You don't think IniRead opens the file to read it? Ever try to read every page of a new book without opening it first? Anyway.... If you know the Section and the Key you are looking for, that's fine... but if you don't know the section, then just use FileRead. 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. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 23, 2007 Moderators Share Posted September 23, 2007 Haha, that's pretty dumb of me. So a file can be 'invisibly' opened because when IniRead runs, I ain't see no opened file.Anyways, the script works. You can refer to my completed script above.On thing though with file reading, I can't remove my pendrive even though 'autorun.inf' in it(i use it to change the drive icon) does not contain any of the aforementioned strings. I guess it must be reading...and reading...the file but i know it can be solved with a simple script 'pause'.Thanks again for the help. Well you are in a continuous loop, with no condition for TrayGetMsg(), so it's going to check the drives over and over very fast forever. You should probably set the condition to only check when you do something with that TrayGetMsg() . 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. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 23, 2007 Moderators Share Posted September 23, 2007 So how do I set the condition for TrayGetMsg()?Look in the help file for an example?Search the forum for that exact term for an example? 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. 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