I use the filename () function to get and write in a text file the file names in a given path. For example, for hhd01, hhd02,...,hhd(n) files contained in the "HHData" folder, I get:
C:\MySurvey\HHdat\hhd01.csdb
C:\MySurvey\HHdat\hhd02.csdb
....
On Android devise I cet :
/storage/emulated/0/csentry/MySurvey/HHdata/hhd01.csdb
.....
I want to use this file for another program using the "FileRead" function, and as you noticate with me, it would be complicated to use the same function at a time on PC as well as on Android devise.
So, I would like to know how to get only the file name (hhd01, hhd02, ...) instead of having the path included as described above.
Yours advises please ???
Filename function
Forum rules
New release: CSPro 8.0
New release: CSPro 8.0
Re: Filename function
There is no built in function to extract just the name. You can use loop through the string from the end going backwards to find the last / and then take the substring from the last / to the end of the string.
Re: Filename function
It's really interesting. I tried something like this, with two counters "i" and "j", one that takes the lengh of the whole string, and the other that counts from a special character ";" or "space" in evolving by 1 or -1. But it didn't work, I didn't I did not succeed to do it.I had to do it manually by counting the positions on the string, and as soon as something changes, it's screwed up.
Dear Josh !!! Can I have an example please? If it's not too much
Thanks
Dear Josh !!! Can I have an example please? If it's not too much
Thanks
Sincerely yours !
-
- Posts: 1777
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Filename function
Here is a function that you can use:
function string GetFilename(string full_path)
// calculate where the directory slash is
do numeric counter = length(full_path) while counter > 1 by -1
if full_path[counter:1] in '/','\' then
exit full_path[counter + 1];
endif;
enddo;
// return the full path if no slash was found
exit full_path;
end;
// calculate where the directory slash is
do numeric counter = length(full_path) while counter > 1 by -1
if full_path[counter:1] in '/','\' then
exit full_path[counter + 1];
endif;
enddo;
// return the full path if no slash was found
exit full_path;
end;