is it a directory?

Post

Posted
Rating:
#1 (In Topic #1423)
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
 I am trying to do something seemingly easy.
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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
IsDir(sPath) As Boolean
 :)
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Greetings.
This is my solution.

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   'Dim MyString As String = "blah_blah_blah"
  4.   'Dim MyString as string = User.Home
  5.   Dim MyString As String = User.Home &/ ".config/gambas3/gambas3.conf"
  6.  
  7.   Message(TestString(MyString))
  8.  
  9.  
  10.  
  11.   Dim RetStr As String = "Just a string"
  12.  
  13.     If Stat(InStr).Type = gb.Directory Then RetStr = "String is a directory"
  14.     If Stat(InStr).Type = gb.File Then RetStr = "String is a file"
  15.  
  16.   Return RetStr
  17.  

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
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
 Perfect bruce. thank you again I knew it was easy just didn't know the word and apparently neither did and of the Very Artificial intelligence or most other posters.

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.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 Was too focused on the problem to notice that. Very bad practice on my part although Gambas did not give any warnings.

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
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

sadams54 said


on a side note, for the 2nd solution…. aren't you concerned using instr as a variable which is also a command?

and

Quincunxian said

Very bad practice on my part although Gambas did not give any warnings.
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".
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" :|)  And it can be used locally in the method as a variable.

cheers
thatbruce

Online now: No Back to the top
1 guest and 0 members have just viewed this.