Goto main content

mkdir

Use to create a directory.

MKDIR

NAME

mkdir - Used to create a directory.

SYNOPSIS

mkdir([permissions:integer, owner:"rwx", group:"rwx", other:"rwx",] "directories");

DESCRIPTION

This function is used to create directories. The user can create several directories at the same time. If the user does mkdir("/a/b/c/d/e") where a,b,c,d and e do not exist, all directories will be created.

The permissions of the directory can be specified using:

permissions:UREAD|UWRITE.

Other permissions can be added using the Owner, Group or other functions.

The user can also include the file "/includes/extenso.sn" which contains definitions for the different permissions:

Note: In the followings examples, the _ between the { should be removed to make it work.

%include "/includes/extenso.sn";

{_{
// Definitions for function stat
%define FILE_SOURCE_PERMS   0x1000;                             // Copy source file's permissions

// Definitions for set file permissions
%define USETID                  0x8000;                                 /* Set user id */
%define UREAD                   0x0400;                                 /* Read by user */
%define UWRITE                  0x0200;                                 /* Write by user */
%define UEXECUTE                0x0100;                                 /* Execute by user */

%define GSETID                  0x4000;                                 /* Set group id */
%define GREAD                   0x0040;                                 /* Read by group */
%define GWRITE                  0x0020;                                 /* Write by group */
%define GEXECUTE            0x0010;                                     /* Execute by group */

%define WSTICKY                 0x2000;                                 /* Sticky bit */
%define WREAD                   0x0004;                                 /* Read by others */
%define WWRITE                  0x0002;                                 /* Write by others */
%define WEXECUTE                0x0001;                                 /* Execute by others */

%define OS_DEFAULT              0x0FFF;                                 /* use OS's default permissions */

}}

EXAMPLES

Note: In the followings examples, the _ between the { should be removed to make it work.

res={_{
        %include "/includes/extenso.sn";
        rmdir("/tmp/abc");
        mkdir(owner:"rw",group:"rwx",other:"x","/tmp/abc");
        -e "/tmp/abc";
        a=stat("/tmp/abc");
        printf(" %x",a.fileperms);
        }}.), qq(res=true 651.));

res={_{
        %include "/includes/extenso.sn";
        rmdir("/tmp/abc");
        mkdir(permissions:UREAD|UWRITE|UEXECUTE|GREAD|GWRITE|GEXECUTE|WWRITE|WREAD|WEXECUTE,"/tmp/abc");
        -e "/tmp/abc";
        a=stat("/tmp/abc");
        printf(" %x",a.fileperms);
        }}.), qq(res=true 755.));


res={_{
        %include "/includes/extenso.sn";
        rmdir("/tmp/abc");
        mkdir(permissions:UWRITE|UREAD,group:"rwx","/tmp/abc");
        -e "/tmp/abc";
        a=stat("/tmp/abc");
        printf(" %x",a.fileperms);
        " "; a.fileperms & WWRITE != 0;
        " "; a.fileperms & UWRITE != 0;
        " "; a.fileperms & GWRITE != 0;
        " "; a.fileperms & GREAD != 0;
        rmdir("/tmp/abc");
        " "; -e "/tmp/abc";
        }}. return res=true 650 false true false true false.


res={_{ mkdir(date:"...",atdate:"...","/tmp/xxx"); }}. return Parameter date is not valid
res={_{ mkdir(owner:"abc","/tmp/abc"); }}. return Invalid perms for owner.
res={_{ mkdir(group:"abc","/tmp/abc"); }}. return Invalid perms for group
res={_{ mkdir(other:"abc","/tmp/abc"); }}. return Invalid perms for other
res={_{ %include "/includes/extenso.sn";
        rmdir("/tmp/abc");
        mkdir("/tmp/abc");
        -e "/tmp/abc"; a=stat("/tmp/abc");
        printf("%x",a.fileperms);
        "wwrite="; a.fileperms & WWRITE != 0;
        "uwrite="; a.fileperms & UWRITE != 0;
        rmdir("/tmp/abc");
        -e "/tmp/abc";
        rmdir("/tmp/abc");
        rmdir("/tmp/abc");
        rmdir("/tmp/abc");
        rmdir("/tmp/abc");
        mkdir("/tmp/abc/def/ghi");
        -e "/tmp/abc/def/ghi";
        rmdir("/tmp/abc");
        -e "/tmp/abc";
        rmdir(recursive:true,"/tmp/abc");
        -e "/tmp/abc";
        }}. return res=true755wwrite=falseuwrite=truefalsetruetruefalse.

res={_{
        %include "/includes/extenso.sn";
        mkdir(permissions:UWRITE|UREAD,"/tmp/abc");
        -e "/tmp/abc"; a=stat("/tmp/abc");
        printf(" %x",a.fileperms);
        " "; a.fileperms & WWRITE != 0;
        " "; a.fileperms & UWRITE != 0;
        rmdir("/tmp/abc");
        " "; -e "/tmp/abc";
        }}. return res=true 600 false true false.

SEE ALSO

{{ include("includes/files.sn") }}

AUTHOR

Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

Edit

© 2024 extenso Inc. All rights reserved.