Public Sub Main()
Dim sList As String[]
Dim sTemp As String
Dim sPattern As String = "*.png"
sList = Dir(User.home, sPattern, gb.file)
For Each sTemp In sList
Print sTemp
Next
End
List only the files without extensions
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
List only the files without extensions
If I run the code below I will get a list of all the files ending in '.png' in my Home directory. Is there a way to list ONLY the files with no extension?
Re: List only the files without extensions
This will do it:-
...but you probably want a solution using sPattern
Code: Select all
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
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: List only the files without extensions
Thanks SteveDee,
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. viewtopic.php?f=9&t=502
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. viewtopic.php?f=9&t=502
Re: List only the files without extensions
OK, try adding the Start argument:-
If InStr(sTemp, ".", 2) = 0 Then
Re: List only the files without extensions
I really do not get the LIKE syntax. It would be nice if there was a flag that could be set that would allow one to use RegEx. To me something like this "*[^.]*" should have worked, but it doesn't...
I'm asking on the new mailing list at list.gambas-basic.org
http://lists.gambas-basic.org/pipermail ... 00033.html
I'm asking on the new mailing list at list.gambas-basic.org
http://lists.gambas-basic.org/pipermail ... 00033.html
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: List only the files without extensions
Thanks SteveDee, good point.
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'.
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'.
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: List only the files without extensions
Further interesting find. Try the following code that will tell you the extensions of your Home folder's hidden files.
I thought I could use: -
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: -
I thought I could use: -
If File.ext(Folder &/ Name) = "" Then..
But it does not work for files that start with a dot '.'
Public Sub Main()
Dim sList As String[]
Dim sTemp As String
Dim sFolder As String = User.Home
sList = Dir(sFolder, "*", gb.file)
For Each sTemp In sList
If sTemp Not Begins "." Then Continue
Print sTemp & " - Extention = " & File.ext(sFolder &/ sTemp)
Next
End
Or try it here https://gambas-playground.proko.eu/?gis ... 3390b0d32e 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: -
Public Sub Main()
Dim sList As String[]
Dim sTemp As String
Dim sFolder As String = User.Home
sList = Dir(sFolder, "*", gb.file)
For Each sTemp In sList
If sTemp Not Begins "." Then Continue
If File.ext(sFolder &/ sTemp) And File.BaseName(sFolder &/ sTemp) = "" Then
Print "Extention = NONE\t" & sTemp
Else
Print "Extention = " & File.ext(sFolder &/ sTemp) & " \t" & sTemp
End If
Next
End
Output
Code: Select all
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
Re: List only the files without extensions
Hello cogier
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.
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.
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: List only the files without extensions
Thanks everyone for your help. I'm getting there. If you want to see what it was all about you can see progress here https://github.com/charlie-ogier/Find_In_Files. If you do test the program please report any bugs, an email address is in the "About" section.