List only the files without extensions
Posted
#1
(In Topic #139)
Guru

Posted
Regular

Code
Public Sub Main()
Dim sList As String[]
Dim sTemp As String
Dim sPattern As String = "*"
sList = Dir(User.home, sPattern, gb.file)
For Each sTemp In sList
If InStr(sTemp, ".") = 0 Then
Print sTemp
Endif
Next
End
…but you probably want a solution using sPattern
Posted
Guru

I too came up with this solution but I wondered if there was an easier way. There is still a problem with this method as a file like .text which does not have an extension will fail to be displayed so more code is needed.
By the way have a look here regarding putting Gambas code on the forum. http://forum.gambas.on…e/viewtopic.php?f=9&t=502
Posted
Posted
Regular

I'm asking on the new mailing list at list.gambas-basic.org
http://lists.gambas-basic.org/pipermail/user/2017-October/000033.html
Posted
Guru

Jornmo you created a flurry of emails about this. I to tried various 'Like' options with no success. Anyway at least I know that I need to write the code 'by hand'.
Posted
Guru

I thought I could use: - But it does not work for files that start with a dot '.'
Or try it here https://gambas-playgro…c9259a90637bddd3390b0d32e
The output will show all the extensions for files that start with a dot '.'
. . .
.pam_environment - Extention = pam_environment
.xsession-errors.old - Extention = old
. . .
I also found that File.BaseName for a file named .text returns a blank string
Is that a bug? :?
Work around: -
Code (gambas)
Output
Code
Extention = NONE .ICEauthority
Extention = NONE .so_sane_state
Extention = NONE .taskrc
Extention = NONE .node_repl_history
Extention = conf .fonts.conf
Extention = NONE .bash_logout
Extention = NONE .bashrc
Extention = NONE .wget-hsts
Extention = NONE .Xauthority
Extention = NONE .gtk-recordmydesktop
Extention = NONE .sudo_as_admin_successful
Extention = NONE .profile
Extention = NONE .bash_history
Extention = lock .gksu.lock
Extention = NONE .xinputrc
Extention = NONE .pam_environment
Extention = old .xsession-errors.old
Extention = NONE .stuff
Extention = png .TempQRCodeFile.png
Posted
Regular

To see the files without the extension, I use the command:
File.BaseName
Normally just typing File. gambas3 should offer contextual help …
You can also use the command:
File.Ext to see only the file extension …
Or
File.Dir to see the path associated with the file.
Of course if you ask File.BaseName on the name of the file and it is .txt then gambas3 will return an empty string (which is normal)
I hope that will help.
Have a good day.
Posted
Guru

1 guest and 0 members have just viewed this.



