Goto main content

dir

Use to list the file of a directory.

DIR

NAME

dir - Use to list the file of a directory.

SYNOPSIS

dir([filetype:integer,order:"asc|desc",sortby="name|mtime|size",]"directory|files..");

DESCRIPTION

This function is used to list the file of a directory.

The files within the dorectory are sort by parameter sortby in the order or parameter order.

This function can be used as a callback or as a function.

files can be specify using a pattern:

PATTERN: Backslash followed by any character, including another backslash. MATCHES: That character exactly.

PATTERN: ? MATCHES: Any single character.

PATTERN: * MATCHES: Any sequence of zero or more characters. (Note that multiple *s in a row are equivalent to one.)

PATTERN: Any character other than \?*[ or a \ at the end of the pattern MATCHES: That exact character. (Case sensitive.)

PATTERN: [ followed by a class description followed by ] MATCHES: A single character described by the class description. (Never matches, if the class description reaches until the end of the string without a ].) If the first character of the class description is !, the sense of the description is reversed. The rest of the class description is a list of single characters or pairs of characters separated by -. Any of those characters can have a backslash in front of them, which is ignored; this lets you use the characters ] and - in the character class, as well as and ! at the beginning. The pattern matches a single character if it is one of the listed characters or falls into one of the listed ranges (inclusive, case sensitive). Ranges with the first character larger than the second are legal but never match. Edge cases: [] never matches, and [^] and [!] always match without consuming a character.

Note that these patterns attempt to match the entire string, not just find a substring matching the pattern.

Parameter filetype can be used to specify the filetype as defined in /includes/extenso.sn by:

// Definitions for dir
%define REG                         1;
%define DIR                         2;
%define CHR                         3; // character device
%define BLK                         4; // Block device
%define PIPE                        5;
%define LNK                         6; // Link
%define SOCK                        7; // Socket

EXAMPLES

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

res={_{
           for a dir(order:"desc",sortby:"mtime","/") do
               sn_nb; ":"; a.file; " ";
           endfor
    }} return res=0:tmp 1:html 2:logs 3:tests 4:includes 5:tmp-usr-local-website-v5-html-tests-gen.sn 6:extenso .));

res={_{
           a=dir(order:"desc",sortby:"mtime","/");
           for i in a do
                " "; sn_nb; ":"; i.file;
           endfor
    }}.), qq(res= 0:tmp 1:html 2:logs 3:tests 4:includes 5:tmp-usr-local-website-v5-html-tests-gen.sn 6:extenso.));

res={_{
           a=dir(order:"asc",sortby:"mtime","/");
           for i in a do
                " "; sn_nb; ":"; i.file;
           endfor
    }} return res= 0:extenso 1:tmp-usr-local-website-v5-html-tests-gen.sn 2:includes 3:tests 4:logs 5:html 6:tmp.));

res={_{
           a=dir(order:"desc",sortby:"size","/");
           for i in a do
                " "; sn_nb; ":"; i.file; ":"; i.size;
           endfor
    }} return res= 0:html:3060 1:tests:442 2:tmp:170 3:logs:136 4:includes:136 5:extenso:136 6:tmp-usr-local-website-v5-html-tests-gen.sn:30.));

res={_{
           a=dir(order:"asc",sortby:"size","/");
           for i in a do
                " "; sn_nb; ":"; i.file; ":"; i.size;
           endfor
    }} return res= 0:tmp-usr-local-website-v5-html-tests-gen.sn:30 1:extenso:136 2:includes:136 3:logs:136 4:tmp:170 5:tests:442 6:html:3060.));

res={_{
           a=dir("/");
           for i in a do
                sn_nb; ":"; i.file;
           endfor
    }} return res=0:tmp-usr-local-website-v5-html-tests-gen.sn1:tmp2:tests3:logs4:includes5:html6:extenso.));

res={_{
           a=dir(sortby:"name","/");
           for i in a do
                sn_nb; ":"; i.file;
           endfor
    }} return res=0:extenso1:html2:includes3:logs4:tests5:tmp6:tmp-usr-local-website-v5-html-tests-gen.sn.));

res={_{
           a=dir(order:"desc",sortby:"name","/");
           for i in a do
                sn_nb; ":"; i.file;
           endfor
    }} return res=0:tmp-usr-local-website-v5-html-tests-gen.sn1:tmp2:tests3:logs4:includes5:html6:extenso.));

res={_{ a=dir("/tests/*.snc");
           for(i=0;i<a.length();++i) do
                i; " " ; a[i].file; " ";
           endfor
    }} return res=0 sample.snc 1 test-read-generate.snc .));

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

© 2021 extenso Inc. All rights reserved.