Unc3nZureD Posted July 2, 2012 Share Posted July 2, 2012 (edited) Hi guys, Here my code is: Func _DirGetWrongFiles() $ForbiddenFiles = _FileListToArray(@ScriptDir, "*", 1) $Count = 1 While 1 If StringRight($ForbiddenFiles[$Count], 3) <> "exe" or "cfg" or "ini" or "txt" Then $Delete = FileDelete(@ScriptDir & "/" & $ForbiddenFiles[$Count]) If $Delete = 0 Then Msgbox(0,"","Forbidden File Found" & @CRLF & $ForbiddenFiles[$Count]) EndIf $Count = $Count + 1 If $Count = $ForbiddenFiles[0] + 1 Then ExitLoop WEnd EndFunc It will delete every file in the directory. Why? Edited July 2, 2012 by Unc3nZureD Link to comment Share on other sites More sharing options...
Zedna Posted July 2, 2012 Share Posted July 2, 2012 (edited) Instead of this If StringRight($ForbiddenFiles[$Count], 3) <> "exe" or "cfg" or "ini" or "txt" Then use something like this $ext = StringRight($ForbiddenFiles[$Count], 3) If $ext <> "exe" or $ext <> "cfg" or $ext <> "ini" or $ext <> "txt" Then EDIT: Shouldn't be there AND instead of OR? Edited July 2, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Unc3nZureD Posted July 2, 2012 Author Share Posted July 2, 2012 (edited) AND? How can a 3 letter text be 'txt' and 'exe' too?! (for example) Edited July 2, 2012 by Unc3nZureD Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted July 2, 2012 Share Posted July 2, 2012 (edited) "AND? How can a 3 letter text be 'txt' and 'exe' too?! (for example)"exampleext=exeif exe<> exe (false) or exe <>cfg (true)The result: true or false=always true. Edited July 2, 2012 by DicatoroftheUSA Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
Unc3nZureD Posted July 2, 2012 Author Share Posted July 2, 2012 (edited) In my case I can't understand the 'AND' statement.for example:$ext = "exe"If $ext <> "cfg" or "exe" Then ...Only one has to be true. if th cfg is false it all the same I just need to get if ANY of the list is true.EDIT: LEARNING STATEMENTSEdit2:Argh, still can't understand :SFunc _DirGetWrongFiles() $ForbiddenFiles = _FileListToArray(@ScriptDir, "*", 1) $Count = 1 While 1 $ext = StringRight($ForbiddenFiles[$Count], 3) If $ext <> "exe" or $ext <> "cfg" or $ext <> "ini" or $ext <> "txt" Then $Delete = FileDelete(@ScriptDir & "/" & $ForbiddenFiles[$Count]) If $Delete = 0 Then _HackFound("Forbidden Files Found" & @CRLF & $ForbiddenFiles[$Count]) EndIf $Count = $Count + 1 If $Count = $ForbiddenFiles[0] + 1 Then ExitLoop WEnd EndFuncStill not working :S Edited July 2, 2012 by Unc3nZureD Link to comment Share on other sites More sharing options...
BrewManNH Posted July 2, 2012 Share Posted July 2, 2012 Here's some pseudo code to explain why it has to use AND and not OR.$ext = "exe" If $ext <> "exe" then delete the file ; pretty simple if it's not exe then delete If $ext <> "exe" Or $ext <> "cfg" Then delete the file ; using Or says if Either one is true delete the file, in this case, it doesn't match "cfg" so the file is deleted If $ext <> "exe" AND $ext <> "cfg" then delete the file ; Using AND says if ALL matches are false then delete the file, if ANY extension matches then skip it, because $ext = "exe" that comparison is true, and we don't want to delete the fileYou can't just string the conditional checks together the way you did, you have to do a comparison for every extension you're looking for. So you need AND $ext <> before every case. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted July 2, 2012 Share Posted July 2, 2012 Computer logic1 = true0 or 0 = 01 or 0 = 11 or 1 = 10 and 0 = 01 and 0 = 01 and 1 = 1eg:if exe<> exe or exe <>cfgis logically equivalent to: 0 or 1 = 1or another eg:if abc<> exe or abc <>cfgis logically equivalent to: 1 or 1 = 1So effectively your expression is always true. Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
Reg2Post Posted July 2, 2012 Share Posted July 2, 2012 AND? How can a 3 letter text be 'txt' and 'exe' too?! (for example)I think you are thinking along the lines of "=" (Equal to) where your code is "<>" (Not equal to). Yes, you cannot have $ext = exe AND $ext = txt (for the sake of this conversation). But you can have $ext <> exe AND $ext <> txt. Link to comment Share on other sites More sharing options...
Exit Posted July 2, 2012 Share Posted July 2, 2012 If Not StringInStr("exe cfg ini txt",$ext) Then FileDelete(........) App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Mechaflash Posted July 2, 2012 Share Posted July 2, 2012 Using AND makes it so that ALL rules must apply. Using OR makes it so that ANY rules apply. So when you say If $ext <> exe OR $ext <> txt, they negate eachother. So if the file is a .txt, it sees the first statement "If $ext <> exe" so automatically it thinks, "It's not exe so then perform the action." If it is exe, then it looks at the first statement, "it's an exe... look at the next statement", and it sees "If $ext <> txt", "well it's not txt so then perform the action." So those first two statements alone targets all file extensions Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
John Posted July 2, 2012 Share Posted July 2, 2012 I still make this mistake sometimes.. Luckily I don't have to ask what went wrong. 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