quietriot Posted August 21, 2010 Share Posted August 21, 2010 Hello, I ve just started using autoit, so im basically a noob but heres my proble, Im making a script, and a portion of it requires autoit to check for a folder on a partition of my harddisc so i used- If FileExists("F:\NAME") then exit but heres the deal if the file is not found, i want to perform some actions which i can define but what i want the script to do next is after performing those actions go back to "If FileExists("F:\NAME") then exit" and recheck again for the folder if the folder is not found again perform those steps, so what i want is that the script should keep moving in loop until the file is not found.. i hope i have explained it understandable . thanks pls help.. Link to comment Share on other sites More sharing options...
cageman Posted August 21, 2010 Share Posted August 21, 2010 (edited) while 1 sleep(50) if NOT FileExists("F:\NAME") Then ;do something endif Wend Edited August 21, 2010 by cageman Link to comment Share on other sites More sharing options...
quietriot Posted August 21, 2010 Author Share Posted August 21, 2010 thanks a million it works , what exactly does "while 1" do? Link to comment Share on other sites More sharing options...
Tvern Posted August 21, 2010 Share Posted August 21, 2010 It's a loop While <statement> <code> WEnd <other code> The code between While and WEnd is repeated untill the statement is false. Because the number 1 is never false the loop keeps repeating. You can only leave a loop like this using Exitloop, Exit, or Return (when in a function) If the loop ends because the statement is false, or Exitloop is reached the other code is executed. (the script continues from WEnd) Link to comment Share on other sites More sharing options...
quietriot Posted August 21, 2010 Author Share Posted August 21, 2010 ok ran into another little problem, even though the script is running into loop fine when the file not exists, but it keeps running even after the file is found, how do i tell it to exit script if the file is found? Link to comment Share on other sites More sharing options...
Tvern Posted August 21, 2010 Share Posted August 21, 2010 There are a few ways to do it, but if you read my last post and this. You should be able to have an idea for atleast one.IF you think you have the solution, but it doesn't work, post your attempt. Link to comment Share on other sites More sharing options...
quietriot Posted August 21, 2010 Author Share Posted August 21, 2010 (edited) Yes, thanks I got it, i read ure post about how to exit the loop and i added this line in the above script ;- while 1 sleep(50) if FileExists("F:\NAME") Then Exit if NOT FileExists("F:\NAME") Then ;do something endif Wend Thank you both "cageman" and " Tvern" Edited August 21, 2010 by quietriot Link to comment Share on other sites More sharing options...
Tvern Posted August 21, 2010 Share Posted August 21, 2010 Glad you got it. You can optimize your code to be a bit more efficient and readable though: while 1 sleep(50) If FileExists("F:\NAME") Then Exit Else ;do something EndIf WEnd See if you also understand how the following work: While FileExists("F:\NAME") <> 1 ;this time I changed the statement to exit the loop (If the file exists the statement becomes false) sleep(50) ;do something WEnd or Do ;this is another sort of loop sleep(50) ;do something Until FileExists("F:\NAME") ;Do ... Until loops exit when the statement is true rather than false The codes all do roughly the same. Link to comment Share on other sites More sharing options...
quietriot Posted August 21, 2010 Author Share Posted August 21, 2010 ow man i was trying to do it with do/until loop but couldn't succeed,will it keep looping untill file is found, ill try with this loop, ure genius man, thanks although i cudnt understand this one While FileExists("F:\NAME") <> 1.... what exactly does this "<>" do? sorry im such a noob Link to comment Share on other sites More sharing options...
BrewManNH Posted August 21, 2010 Share Posted August 21, 2010 while 1 sleep(50) If FileExists("F:\NAME") Then Exit Else ;do something EndIf WEnd See if you also understand how the following work: While FileExists("F:\NAME") <> 1 ;this time I changed the statement to exit the loop (If the file exists the statement becomes false) sleep(50) ;do something WEnd or Do ;this is another sort of loop sleep(50) ;do something Until FileExists("F:\NAME") ;Do ... Until loops exit when the statement is true rather than false The codes all do roughly the same. Actually they don't do roughly the same thing. The first statement will not execute if the file exists as soon as it is run, the Do loop will run at least once even if the file exists which is probably not what the OP wants to have happen. Big difference in execution if you don't want the file to get deleted or overwritten unnecessarily. 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...
cageman Posted August 21, 2010 Share Posted August 21, 2010 (edited) do sleep(100) ;do something until FileExists("F:\NAME")little help with the code, it will exit the loop if a file is found because FileExists() returns 1 (which is the same as the boolean value true) when a file is found and do until keeps looping until the expression after until is true. Hope you got it. Just see someone above me posted the same thing, but oke 2 examples can't hurt. Edited August 21, 2010 by cageman Link to comment Share on other sites More sharing options...
Tvern Posted August 21, 2010 Share Posted August 21, 2010 "<>" is an operator. In this case it can be seen as the opposite of "=" so (1=1) evaluates as true, while (1<>1) evaluates as false.In other wording "<>" is only false if the value before and after it are the same, while "=" is only true if the values are the same.When FileExist doesn't find a file it returns 0, so you can see it like this:While FileExists("F:\NAME") <> 1becomes While 0 <> 10<>1 is True, so the loop keeps running. If the File is found though, FileExist returns 1, so you can see it like this:While FileExists("F:\NAME") <> 1becomes While 1 <> 11<>1 is false, so the loop exits.It is wise to bookmark the operators page until you know them by heart. You will need them very often. Link to comment Share on other sites More sharing options...
quietriot Posted August 21, 2010 Author Share Posted August 21, 2010 yes i get it, my statements still states "IF" where there is ";do something", so do/until does the trick as well, so its like this do if .. if .. until (file is found) but i get it if those were unconditional commands they might get executed b4 the file check. right.. and this one does for me as well while 1 sleep(50) If FileExists("F:\NAME") Then Exit Else ;do something EndIf WEnd as i just need the file check, if it exists then the script exits nice n clean if it does not exists the script just keep going back again in loop. thanks everyone, ure all so kind . Link to comment Share on other sites More sharing options...
quietriot Posted August 21, 2010 Author Share Posted August 21, 2010 "<>" is an operator. In this case it can be seen as the opposite of "=" so (1=1) evaluates as true, while (1<>1) evaluates as false. In other wording "<>" is only false if the value before and after it are the same, while "=" is only true if the values are the same. When FileExist doesn't find a file it returns 0, so you can see it like this: While FileExists("F:\NAME") <> 1 becomes While 0 <> 1 0<>1 is True, so the loop keeps running. If the File is found though, FileExist returns 1, so you can see it like this: While FileExists("F:\NAME") <> 1 becomes While 1 <> 1 1<>1 is false, so the loop exits. It is wise to bookmark the operators page until you know them by heart. You will need them very often. ok...em.. so if i put while fileexists("F:\NAME") = 1 ;do somethine wend and file is found will it exit or continue loop? what im saying is if the file is found ,the fileexist will return 1 or 0? Link to comment Share on other sites More sharing options...
Tvern Posted August 21, 2010 Share Posted August 21, 2010 Click the FileExists linky in my post or search for FileExists in the helpfile. (press F1 in Scite) The answer is there. Link to comment Share on other sites More sharing options...
quietriot Posted August 21, 2010 Author Share Posted August 21, 2010 yes, thanks and sorry, i get it , if the file is found it will return 1 coz its a success so while fileexists("F:\NAME") = 1 ;do somethine wend this will become 1=1 and it will continue the loop even if the file is found, which i dont want so therefore <> as u stated is opposite of =,hence does the trick thank u so much 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