Hi!!
With this code:
ok = OPENFILE(channel%, file$, mode%)
I get the full path to my file. But, how do I get just the name of my file?
You would have to work it out yourself unfortunately - the name is precedent by either a \ or / (or perhaps nothing at all).
"get"? Did you mean FILEREUEST$? I don't understand the question.
You can use this function to retrieve the file name portion from a full path:
FUNCTION File_GetName$: path$, slash$="/"
LOCAL slash%
slash = REVINSTR(path$, slash$)
IF slash <=0 THEN RETURN path$
RETURN MID$(path$, slash+1)
ENDFUNCTION
It's usage:
DEBUG(File_GetName$("//Web/WorldWide"))
DEBUG(File_GetName$("Internet"))
DEBUG(File_GetName$("../Graphics/pics/"))
DEBUG(File_GetName$("C:\\GLBasic\\Rocks.com", "\\"))
Note the need for the double '\\' when using that slash.
Outputs:
WorldWide
Internet
Rocks.com
Yes Kitty. If I use file$=FILEREQUEST$(TRUE, "Text|*.txt|All|*.*") I have the same problem.
file$ returns the full path and I just need the name of that file and extension.
Wow Slydog!!. A function that checks where is the last "/" to get the file name. Great!!!
Many thanks!!
Data stripping is important obviously.
Recently, i needed to know which files were bmp and png.
So here is how i checked for file extensions..
GLOBAL splits$[]
splitnum=SPLITSTR( M.List$, splits$[], "." ) //split everything with dots to check file ext
FOR j=0 TO splitnum-1
IF (splits$[j] = "bmp") OR (splits$[j] = "BMP") THEN IsImg=TRUE
IF (splits$[j] = "png") OR (splits$[j] = "PNG") THEN IsImg=TRUE
NEXT
IF IsImg=TRUE then ...blahblahblah
that would return true for "bmp.png"
Better: IF LCASE$(RIGHT$(filename$, 4)) = ".png" ...
Quote from: Kitty Hello on 2011-Jan-10
that would return true for "bmp.png"
Better: IF LCASE$(RIGHT$(filename$, 4)) = ".png" ...
Cool, Thanks, fixing it now!
SELECT LCASE$(RIGHT$(M.List$[i], 4))
CASE ".bmp"; IsImg=TRUE
CASE ".BMP"; IsImg=TRUE
CASE ".png"; IsImg=TRUE
CASE ".PNG"; IsImg=TRUE
DEFAULT; IsImg=FALSE
ENDSELECT
Why do you need to check for uppercase extensions when using LCASE$() ? :S
Dont you hate redundancies? :bed:
CASE ".bmp" OR ".png"; IsImg = TRUE
Thanks :)
Woops that made the IDE go crazy with errors.
CGStr' to `bool' is ambiguous
you can say that again.
CASE ".bmp"; IsImg = TRUE
CASE ".png"; IsImg = TRUE
this works