Creating a directory¶
mkdir() |
Create a directory |
SYNTAX
mkdir(pathname, mode)
Creates the directory specified in pathname. The user must have permission to create files in the parent directory.
The mode is the access permission required for the new directory. This argument is ignored on MSDOS/Windows, but should be set to a sensible value in case this changes in the future. The possible values for mode (which are the same as for the chmod()function) are defined in the standard include file $SCULPTOR/include/files.h, and are as follows:
PERMS_RDOWNER |
Give owner read permission |
PERMS_WROWNER |
Give owner write permission |
PERMS_EXOWNER |
Give owner execute permission |
PERMS_RDGROUP |
Give group read permission |
PERMS_WRGROUP |
Give group write permission |
PERMS_EXGROUP |
Give group execute permission |
PERMS_RDOTHER |
Give others read permission |
PERMS_WROTHER |
Give others write permission |
PERMS_EXOTHER |
Give others execute permission |
These modes can be combined using the | operator. Common combinations of the modes are also defined in $SCULPTOR/include/files.h.
The function returns zero if successful; otherwise it returns -1 and assigns the operating system error code to sys.Errno.
NOTES
Under UNIX, a user can only get a list of files in a directory if the directory has execute permission.
EXAMPLES
mkdir("/usr/tim/games", PERMS_RDOWNER | PERMS_WROWNER | PERMS_EXOWNER)
This example tries to create a user configuration directory if one doesn’t already exist:
!temp SculptorDir,,a170
!temp SCDefaultDir,,a170
!temp ConfigDir,,a170
SculptorDir = getenv("SCULPTOR")
SCDefaultDir = tmp.SculptorDir / _FSLASH / "default"
switch (sys.LoggedOnUser) {
case = "":
ConfigDir = SCDefaultDir
break
default:
ConfigDir = SCDefaultDir / _FSLASH / sys.LoggedOnUser
break
}
if (access(ConfigDir, TEST_EXISTS) = _NOTFOUND) {
if (mkdir(ConfigDir, PERMS_RWXRWXRWX) <> 0) {
error "Unable to create user configuration directory.", \
"Program will use the configuration in $SCULPTOR/default."
ConfigDir = SCDefaultDir
}
}
RELATED TOPICS |