is it a directory?
Posted
#1
(In Topic #1423)
Enthusiast

I get a string in. I want to know if that string is a directory.
I am searching all over and all I get are incorrect examples using "isdirectory" that does not seem to exist in gambas 3.19.4 such as file.isdirectory or dir.isdirectory.
I am sure it is simple but for some reason it is not showing up on any kind of search. Please Help.
Posted
Guru

Posted
Expert

This is my solution.
Code (gambas)
- 'Dim MyString As String = "blah_blah_blah"
- 'Dim MyString as string = User.Home
- Return RetStr
I had to test for EXIST first as the STAT method returns an error if it is not either a file or directory.
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Enthusiast

spoke too soon. Tried both solutions out and they both fail.
the isdir seems to always return false no matter what is sent to it.
the other solution fails saying the file or directory does not exist even though it does.
on a side note, for the 2nd solution…. aren't you concerned using instr as a variable which is also a command?
UPdate UPDATE::::
the isdir does work but I had to use trim on the incoming result removing erroneous space that made the result wrong. I am working now thank you guys.
Posted
Expert

Is the directory you are passing contain a symbolic link ?
I didn't account for those in the code although the optional parameters allow for it if you choose to add those.
.
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Regular

andsadams54 said
on a side note, for the 2nd solution…. aren't you concerned using instr as a variable which is also a command?
Interesting, but not a real concern. It's interesting that it doesn't raise a warning re "Overriding a reserved word" (or whatever) message but then it isn't really an override in this case, its just a reserved word used as a variable name. The symbol table is not going to be upset in any way as it knows it as a, for want of better words, "data label" and wont be the same as a "method name" or even a "class name". If you change the parameter name to "Class" for instance, the code will still run OK but if you compile the project you'll get a Warning "Class name hidden by local declaration: Class".Quincunxian said
Very bad practice on my part although Gambas did not give any warnings.
Putting it another way, you can call a parameter name anything you like, including even a data type. It is just a label in the symbol table pointing to a bit of data. (try it with a parameter called "Integer"
cheers
thatbruce
1 guest and 0 members have just viewed this.

