Sign in to follow this  
Followers 0
Skizmata

How do I make a Func IsDirectory()

9 posts in this topic

How would you make a IsDirectory() function in AutoIt.

Perl sub example...

sub IsDirectory() {
    $target = shift();
    return 1 if (-d $target);
    return 0;
}

AutoIt changed my life.

Share this post


Link to post
Share on other sites



Func _IsDirectory($s_file)
    Return StringInStr(FileGetAttrib($s_file), "D")
EndFunc


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Thanks guys! Perfect!


AutoIt changed my life.

Share this post


Link to post
Share on other sites

Func _IsDirectory($s_file)
    Return StringInStr(FileGetAttrib($s_file), "D")
EndFunc

Very close to mine! The only diffrence is that yours will return the offset of the letter D, which should be 3?

A better Idea would be to do this:

Func _IsDirectory ($sDir)
   Return StringInStr (FileGetAttrib ($sDir), "D") <> 0
EndFunc ; ==> _IsDirectory

Mat

Share this post


Link to post
Share on other sites

Very close to mine! The only diffrence is that yours will return the offset of the letter D, which should be 3?

A better Idea would be to do this:

Func _IsDirectory ($sDir)
   Return StringInStr (FileGetAttrib ($sDir), "D") <> 0
EndFunc ; ==> _IsDirectory

Mat

If you want a boolean return sure. But as far as "Better", not quite sure where that comes into play.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Additionnally _IsFile (not a directory but really a file)

Func _IsFile ($sFile)
Return Not(StringRegExp (FileGetAttrib ($sFile), "D", 0))
EndFunc ; ==> _IsFile

This return a boolean (true/false)

OR

Func _IsFile ($sFile)
Return Not(StringRegExp (FileGetAttrib ($sFile), "D", 0)) + 0
EndFunc ; ==> _IsFile

This return a number (0(is not a file)/1(is a file))

I can't really test since I use v3.2.0.1

and I don't have StringRegExp but it should work

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