manipulating_20filenames_20and_20pathnames
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
manipulating_20filenames_20and_20pathnames [2018/03/31 13:19] – external edit 127.0.0.1 | manipulating_20filenames_20and_20pathnames [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
===== Root directory ===== | ===== Root directory ===== | ||
**FNf_root()** extracts the root directory from the supplied path. You can't just look for a colon specifying a drive, as the program may have been run with a Uniform Naming Convention path (see [[http:// | **FNf_root()** extracts the root directory from the supplied path. You can't just look for a colon specifying a drive, as the program may have been run with a Uniform Naming Convention path (see [[http:// | ||
- | | + | <code bb4w> |
- | FNf_root(" | + | |
- | FNf_root(" | + | FNf_root(" |
- | FNf_root(" | + | FNf_root(" |
+ | FNf_root(" | ||
+ | </ | ||
You could then do, for example: | You could then do, for example: | ||
+ | <code bb4w> | ||
PROCcopyfiles(FNf_root(indir$)+" | PROCcopyfiles(FNf_root(indir$)+" | ||
+ | </ | ||
\\ | \\ | ||
===== Extracting leafname ===== | ===== Extracting leafname ===== | ||
**FNf_leaf()** will scan through a fully-qualified pathname to find just the leafname - the final part of the path.\\ | **FNf_leaf()** will scan through a fully-qualified pathname to find just the leafname - the final part of the path.\\ | ||
+ | <code bb4w> | ||
DEF FNf_leaf(A$) | DEF FNf_leaf(A$) | ||
LOCAL A%: | LOCAL A%: | ||
UNTILA%=0: | UNTILA%=0: | ||
+ | </ | ||
For example, **FNf_leaf(" | For example, **FNf_leaf(" | ||
===== Removing leafname ===== | ===== Removing leafname ===== | ||
**FNf_path()** will remove the leafname, keeping just the pathname. For example: | **FNf_path()** will remove the leafname, keeping just the pathname. For example: | ||
+ | <code bb4w> | ||
DEF FNf_path(A$): | DEF FNf_path(A$): | ||
LOCAL A%: | LOCAL A%: | ||
+ | </ | ||
This lets you use code such as:\\ | This lets you use code such as:\\ | ||
+ | <code bb4w> | ||
IF out$="" | IF out$="" | ||
+ | </ | ||
\\ | \\ | ||
===== Removing filename extension ===== | ===== Removing filename extension ===== | ||
**FNf_noext()** will remove an extension from a pathname. Note that you cannot just remove the last four characters, as the extension is not guaranteed to be four characters (eg, " | **FNf_noext()** will remove an extension from a pathname. Note that you cannot just remove the last four characters, as the extension is not guaranteed to be four characters (eg, " | ||
+ | <code bb4w> | ||
DEF FNf_ext(A$): | DEF FNf_ext(A$): | ||
LOCAL A%: | LOCAL A%: | ||
IF MID$(A$, | IF MID$(A$, | ||
+ | </ | ||
You can then use this to do, for example: | You can then use this to do, for example: | ||
+ | <code bb4w> | ||
PROCBMP_toGIF(bmpfile$, | PROCBMP_toGIF(bmpfile$, | ||
+ | </ | ||
Note that filenames similar to **" | Note that filenames similar to **" | ||
===== Finding filename extension ===== | ===== Finding filename extension ===== | ||
**FNf_ext()** will scan through a fully-qualified pathname to find the extension. As with **FNf_noext()**, | **FNf_ext()** will scan through a fully-qualified pathname to find the extension. As with **FNf_noext()**, | ||
+ | <code bb4w> | ||
DEF FNf_noext(A$): | DEF FNf_noext(A$): | ||
LOCAL A%: | LOCAL A%: | ||
IFMID$(A$, | IFMID$(A$, | ||
+ | </ | ||
You can then use this to do, for example: | You can then use this to do, for example: | ||
+ | <code bb4w> | ||
runapp$=FNMime_Type(FNf_ext(file$)) | runapp$=FNMime_Type(FNf_ext(file$)) | ||
+ | </ | ||
\\ | \\ | ||
===== Ensuring full absolute pathnames ===== | ===== Ensuring full absolute pathnames ===== | ||
It is good practice for programs to access files via fully-specified paths, yet it can also be useful for programs to be able to access certain files relative to some path, such as the directory the program is running in. **FNf_fullpath()** will take a path and a filename and return the full path of a relative filename.\\ | It is good practice for programs to access files via fully-specified paths, yet it can also be useful for programs to be able to access certain files relative to some path, such as the directory the program is running in. **FNf_fullpath()** will take a path and a filename and return the full path of a relative filename.\\ | ||
+ | <code bb4w> | ||
DEF FNf_fullpath(path$, | DEF FNf_fullpath(path$, | ||
IF INSTR(file$,":" | IF INSTR(file$,":" | ||
IF RIGHT$(path$, | IF RIGHT$(path$, | ||
=path$+file$ | =path$+file$ | ||
+ | </ | ||
It functions as in the following examples.\\ | It functions as in the following examples.\\ | ||
- | | + | <code bb4w> |
- | FNf_fullpath(" | + | |
- | FNf_fullpath(" | + | FNf_fullpath(" |
+ | FNf_fullpath(" | ||
+ | </ |
manipulating_20filenames_20and_20pathnames.1522502368.txt.gz · Last modified: 2024/01/05 00:17 (external edit)