|
The OSPATH() function performs actions on operating system files.
Format
OSPATH(path, key)
OSPATH(path, key, qualifier)
where
| path | evaluates to a pathname. |
| key | identifies the action to be performed. |
| qualifier | provides additional information for the action to be performed. |
The OSPATH() function returns information about path. The values of key and their associated actions are as below. The key names in the second column are defined in the KEYS.H include record in the SYSCOM file.
0
|
OS$PATHNAME
|
Test if path is a syntactically valid pathname (True/False).
|
1
|
OS$FILENAME
|
Test if path is a syntactically valid filename (True/False).
|
2
|
OS$EXISTS
|
Test if path exists as either file or directory (True/False).
|
3
|
OS$UNIQUE
|
Returns a unique file name.
|
4
|
OS$FULLPATH
|
Return full path name of path. On case insensitive file systems, the returned path will be upper case.
|
5
|
OS$DELETE
|
Deletes path. Returns success (True/False).
|
6
|
OS$OPEN
|
Check if file is open by pathname (True/False).
|
7
|
OS$DTM
|
Returns date/time modified of path as an epoch value, zero if path does not exist.
|
8
|
OS$FLUSH.CACHE
|
Flush dynamic file cache in local process. Always returns True.
|
9
|
OS$FULLPATHX
|
Return full path name of path, preserving casing.
|
10
|
OS$PARENT
|
Return parent directory of path. If path is a top level directory, the same pathname is returned.
|
11
|
OS$UID
|
Get UID of path (not Windows), zero if path does not exist.
|
12
|
OS$GID
|
Get GID of path (not Windows), zero if path does not exist.
|
13
|
OS$MKDIR
|
Creates directory path. Returns success (True/False).
|
14
|
OS$MKPATH
|
Creates directory path and any intermediate levels. Returns success (True/False).
|
15
|
OS$MODES
|
Returns file access modes of path (not Windows) as the decimal representation of a Linux mode value, zero if path does not exist. See below.
|
16
|
OS$IS.FILE
|
Test if path exists as a file (True/False)
|
17
|
OS$IS.DIR
|
Test if path exists as a directory (True/False)
|
18
|
OS$OWNER
|
Returns the owner of the file (Windows only)
|
19
|
OS$MKFIFO
|
Create named pipe (Linux only)
|
20
|
OS$INFO
|
Returns a dynamic array of information similar to the STATUS statement.
|
21
|
OS$SPACE
|
Returns partition size and available space, separated by a field mark
|
512
|
OS$CHMOD
|
Sets file permissions from qualifier as the decimal representation of a Linux access mode value. See below. Returns success (True/False).
|
513
|
OS$SET.LINK
|
Create a hard link. The qualifier is the name of the link to be created.
|
514
|
OS$SET.UID.GID
|
Set uid and gid for named file. The qualifier is formed from the uid and gid, separated by a comma. These may be given as numeric values or as names. A null name indicates that the uid or gid is not to be changed. The return value is a Boolean value indicating the success of the action. (not Windows).
|
File Permission Values
Use of OS$MODES to retrieve the file access permissions or OS$CHMOD to set permissions is complicated by the conventional use of an octal representation of the bit significant mode value in Linux commands or in C programs. QMBasic has no syntax for an octal constant and hence these actions work with the decimal representation of the modes.
Octal
|
Decimal
|
Meaning
|
400
|
256
|
Owner, read access
|
200
|
128
|
Owner, write access
|
100
|
64
|
Owner, execute access
|
040
|
32
|
Group, read access
|
020
|
16
|
Group, write access
|
010
|
8
|
Group, execute access
|
004
|
4
|
Other, read access
|
002
|
2
|
Other, write access
|
001
|
1
|
Other, execute access
|
Examples
IF NOT(OSPATH(RID, OS$FILENAME)) THEN
DISPLAY 'Not a valid filename'
END
The program fragment above validates a filename.
IF NOT(OSPATH('MYFILE', OS$SET.UID.GID, '100,staff')) THEN
DISPLAY 'Error ' : OS.ERROR() : ' setting uid/gid'
END
The program fragment above updates ownership of MYFILE.
OK = OSPATH('MYFILE', OS$CHMOD, ICONV('740', 'MO'))
The statement above sets modes octal 740 on MYFILE. This is more readable than using the decimal equivalent
OK = OSPATH('MYFILE', OS$CHMOD, 480)
|