Dirk98 Posted November 28, 2007 Share Posted November 28, 2007 Hello guys, Could you please paste here a piece of code that checks if a XYZ folder exitst in the path and returns some value if it is not there (does not exists in the path). Many thanks! Dirk. Link to comment Share on other sites More sharing options...
Zedna Posted November 28, 2007 Share Posted November 28, 2007 Hello guys,Could you please paste here a piece of code that checks if a XYZ folder exitst in the path and returns some value if it is not there (does not exists in the path).Many thanks!Dirk.FileExists() - Checks if a file or directory exists. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Dirk98 Posted November 28, 2007 Author Share Posted November 28, 2007 FileExists() - Checks if a file or directory exists.Thank you, Zedna! I used DirMove in my script, but have found it destructive even with 0 flag.Dirk. Link to comment Share on other sites More sharing options...
JerryD Posted November 28, 2007 Share Posted November 28, 2007 While FileExists() will work most of the time, it can return a false positive if a FILE with the name of the DIRECTORY you're looking for exists. For example, let's say you're looking for the DIRECTORY: C:\WINDOWS\system32\drivers\etc\hosts Try DirGetSize() krasnoshtan 1 Link to comment Share on other sites More sharing options...
Dirk98 Posted November 28, 2007 Author Share Posted November 28, 2007 While FileExists() will work most of the time, it can return a false positive if a FILE with the name of the DIRECTORY you're looking for exists. For example, let's say you're looking for the DIRECTORY:C:\WINDOWS\system32\drivers\etc\hostsTry DirGetSize()JerryD, thank you very much for the warning. Could you please elaborate the false positive. I don't understand the example you gave there. But sounds serious for my script.Thanks,Dirk. Link to comment Share on other sites More sharing options...
SpookMeister Posted November 28, 2007 Share Posted November 28, 2007 His example references the "hosts" file. He is warning that if there is a file with the same name as the directory that you are looking for you will get a false positive. Lets say you make a folder called C:\Testing and in it you put a file called "xyz" now if you tried $folder="C:\Testing\xyz" IF FileExist($folder) Then MsgBox(0,"Folder Found","The folder " & $folder & " exists") The IF statement would return as true even though its not really a folder ahmeddzcom and krasnoshtan 1 1 [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Dirk98 Posted November 28, 2007 Author Share Posted November 28, 2007 His example references the "hosts" file. He is warning that if there is a file with the same name as the directory that you are looking for you will get a false positive. Lets say you make a folder called C:\Testing and in it you put a file called "xyz" now if you tried $folder="C:\Testing\xyz" IF FileExist($folder) Then MsgBox(0,"Folder Found","The folder " & $folder & " exists") The IF statement would return as true even though its not really a folder Thanks, SpookMeister, got it. Link to comment Share on other sites More sharing options...
Zedna Posted November 28, 2007 Share Posted November 28, 2007 Then use FileGetAttrib() to clarify file/directory status. $folder="C:\Testing\xyz" IF FileExist($folder) and StringInStr(FileGetAttrib($folder),"D") Then MsgBox(0,"Folder Found","The folder " & $folder & " exists") AnonymousX 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
schilbiz Posted November 28, 2007 Share Posted November 28, 2007 I don't mean to change the subject or continue the topic when it has been resolved but looking into it I tried a few things out. I am wondering if this is sloppy coding, or is it an exceptible way to go about it. The below code would work, but it does not include the #include <Array.au3> or _ArrayDisplay($FileList,"$FileList") #include <File.au3> $FileList = _FileListToArray("C:\" , "*.ini") If @error Then MsgBox(0, "", "File and/or Folder does not exist.") Exit EndIfoÝ÷ Ù8b²Þw%¹×¬¶¦najwp¢¹,"¶+,ºh±çm¡«¢+Ø¥¹±Õ±Ðí¥±¹ÔÌÐì(%¹±Õ±ÐíÉÉä¹ÔÌÐì(ÀÌØí¥±1¥ÍÐô}¥±1¥ÍÑQ½ÉÉä ÅÕ½ÐíèÀäÈí]¥¹½ÝÌÅÕ½Ðì°ÅÕ½Ð쨹¥¹¤ÅÕ½Ðì¤)%ÉɽÈQ¡¸(5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¥±¹½½È½±È½Ì¹½Ðá¥ÍиÅÕ½Ðì¤(á¥Ð)¹%)}ÉÉå¥ÍÁ±ä ÀÌØí¥±1¥ÍаÅÕ½ÐìÀÌØí¥±1¥ÍÐÅÕ½Ðì¤ Would any of you more experienced AutoIt ers use the first example or is it just bad code? Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 28, 2007 Share Posted November 28, 2007 I don't mean to change the subject or continue the topic when it has been resolved but looking into it I tried a few things out.I am wondering if this is sloppy coding, or is it an exceptible way to go about it.The below code would work, but it does not include the#include <Array.au3>or_ArrayDisplay($FileList,"$FileList")Would any of you more experienced AutoIt ers use the first example or is it just bad code?The _ArrayDisplay() was only there for debug/demo purposes and is safely discarded once you have it working for you. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
schilbiz Posted November 28, 2007 Share Posted November 28, 2007 The _ArrayDisplay() was only there for debug/demo purposes and is safely discarded once you have it working for you. Yea,.. thats right, how did you know? Link to comment Share on other sites More sharing options...
AnonymousX Posted August 4, 2017 Share Posted August 4, 2017 On 11/28/2007 at 0:05 PM, Zedna said: Then use FileGetAttrib() to clarify file/directory status. $folder="C:\Testing\xyz" IF FileExist($folder) and StringInStr(FileGetAttrib($folder),"D") Then MsgBox(0,"Folder Found","The folder " & $folder & " exists") 10 years later and post is still helping people. Thanks!!! nicdev007 and Leendert-Jan 2 Link to comment Share on other sites More sharing options...
nicdev007 Posted November 3, 2017 Share Posted November 3, 2017 Thanks, helped me today as well :-) For information though I had to change it to "FileExists($folder)" to make it work. Cheers Life is too short to worry about the things you don't have or cannot do ... So if you don't know how to do it - Learn it! Don't be afraid to ask for help ... 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