Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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()

Posted

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()

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.

Posted

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

[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]

Posted

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.
Posted

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?

Posted

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.

:P

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
Posted

The _ArrayDisplay() was only there for debug/demo purposes and is safely discarded once you have it working for you.

:P

Yea,.. thats right, how did you know? ;)

  • 9 years later...
  • 2 months later...
Posted

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 ...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...