Jump to content
Sign in to follow this  
erifash

Is it a folder?

Recommended Posts

erifash

Here is a quick little function that checks to see if a path belongs to a folder or not:

; Return - Path is folder: True, Path is file: False

Func _IsFolder( $sPath )
    If not FileExists($sPath) Then SetError(1)
    Return not not StringInStr(FileGetAttrib($sPath), "D")
EndFunc

Enjoy!

Share this post


Link to post
Share on other sites
hankjrfan

Isn't this

Return not not StringInStr(FileGetAttrib($sPath), "D")

the same as

Return StringInStr(FileGetAttrib($sPath), "D")

I thought that 2 nots would cancel each other out?

Share this post


Link to post
Share on other sites
erifash

I put that in there because I didn't want a number to be returned, but True or False (boolean). You can remove it if you don't like it.

Share this post


Link to post
Share on other sites
hankjrfan

That is kind of cool I was not aware that "noting" it made it a bool. That is good to know.

Share this post


Link to post
Share on other sites
busysignal

Here is a quick little function that checks to see if a path belongs to a folder or not:

; Return - Path is folder: True, Path is file: False

Func _IsFolder( $sPath )
    If not FileExists($sPath) Then SetError(1)
    Return not not StringInStr(FileGetAttrib($sPath), "D")
EndFunc

Enjoy!

@erifash, just found a use for your function.. Thanks for the post.. I gave you some stars!! :o

Cheers.. B)

Share this post


Link to post
Share on other sites
layer

I made something a while ago, that is not reliable, but at the time I thought it was.

Func _FileOrFolder($path)
   Local $len = StringLen($path)
   If StringMid($path, $len) = "\" Then
      MsgBox(0, "Folder", $path & " is a folder.")
   Else
      MsgBox(0, "File", $path & " is a file.")
   EndIf
EndFunc  ;==>FileOrFolder

_FileOrFolder("C:\Program Files\AutoIt3\AutoIt3.exe")
_FileOrFolder("C:\")

EDIT: The MsgBox's were just for debugging purposes.

Edited by layer

FootbaG

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×