File names |
Topics | |
1. Introduction
2. Examples
3. URL types supported
4. A sub to construct a URL compliant file name
1. Introduction
When using file related functions, such as LoadFile, SaveFile, LoadDatabase,
etc. Of course you can use the normal file name conventions of the platform
you're developing on, but aptilis also understands 'URLs' in order to somehow
bridge the Windows (9x/NT) / Unix gap.
To write a file name you can hence use the notation:
file://path
where path is the path to your file.
On windows platforms, you need to indicate disks as follows:
/disk_letter|
and you also need to replace back slashes by forward slashes.
The vertical bar is know as the 'pipe' character, its ASCII code
is 124
The examples will help you decode all that!
Note that functions such as GetCurrentDirectory return
a file or path name in the format used on your platform.
2. Examples
Normal As you would normally write them |
URL As you can also write them |
---|---|
1. Windows filenames | |
myFile.txt In the current directory, wherever that might be (relative path) | file://myFile.txt |
\someDocs\myFile.txt From the root of the current disk | file:///someDocs/myFile.txt |
D:\someDocs\myFile.txt complete or 'absolute' path | file:///D|/someDocs/myFile.txt |
2. Unix filenames | |
myFile.txt In the current directory, wherever that might be (relative path) | file://myFile.txt |
/someDocs/myFile.txt complete or 'absolute' path, all the way back to the root | file:///someDocs/myFile.txt |
3. URL types supported
All file related functions support the file:// type.
In addition, LoadFile supports the http://, https:// and ftp:// types,
and saveFile understands both the file:// and ftp:// protocols,
allowing you
to load web pages directly into a variable! Note that through the http://
protocol the entire
web page is returned together with its server generated header. Look past the occurence
of "\r\n\r\n" for actual content.
Of course, your computer needs to be connected to the Internet in order
to use the http:// filetype if you want to retrieve files
stored on a web server. You can also retrieve a file from an Intranet
based server you're connected to through a LAN.
4. A sub to construct a URL compliant file name
sub main fn = getCurrentDirectory() url = toUrl(fn) $ print("Original: ", fn$, "\n") print("URL: ", url$, "\n") end main sub toUrl(fileName) if mid(fileName$, 2, 1) = ":" $ es = "/" $ end if fileName = replace(fileName$, ":", "|") $ return "file://" + es + replace(fileName$, "\\", "/") $ end toUrlResult:
Original: C:\aptilis URL: file:///C|/aptilis |