Jump to content

Recommended Posts

Posted

I need to be able to tell whether a file exists, folder exists, or neither.

FileExists will only tell me if something exists, not whether it is a file or folder...

Any help? I'm sure some1 has dealt with this before.

Posted

Nevermind, I think I found a solution.

FileGetAttrib("filename") should do the trick.

O well, maybe this thread will help someone else.

Posted

Hi,

You can check even with FileExists(), it's will check folders as well, but if you need to confirm if this is realy a folder, than you can make a litle function:

Func _IsFolder($sPath)
    Return StringInStr(FileGetAttrib($sPath), "D")
EndFuncoÝ÷ Øêò¢çf¤zØb±Ø«yËeÊÚç$÷è׫DZËljëh×6Func _FolderExists($sPath)
    If Not FileExists($sPath) Then Return False
    Return StringInStr(FileGetAttrib($sPath), "D")
EndFunc

:)

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  Quote

While returning the position of 'D' in the FileGetAttrib works, it's kind of nonsensical, in my opinion.

But in owr case we need to check if dir is exists, and we call this func like this:

If _FolderExists("C:\") Then
   ;;;;
EndIf

If this is folder, then will returned positive number (more then zero (0) - and this is the same as True in this case ), if not, then returned 0, so this is no mether how to check... but for error checking and error returns this function must be expanded... and i has write it just for show how it can be done simple, just to check if given variable/string is a folder :) .

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted (edited)

:) Oh thanks for the explanation. I didn't understand any of that before. :D

Since the number returned isn't actually relevant to identifying if it's a directory that exists or not, you might as well just return true or false (like I did in my example). I was only giving my opinion and it's not something you need to feel defensive about - or even agree with - there are often many solutions to the same end.

I did find it odd how you replied to the original poster with the solution that he had already found on his own, though.

edit - spelling, grammar, crap

Edited by xcal

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