Sign in to follow this  
Followers 0
erifash

Is it a folder?

7 posts in this topic

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



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

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

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

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

#7 ·  Posted (edited)

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  
Followers 0