Scol standard library package  0.3.1
Common and usefull functions for all Scol applications
Functions
The file system API.

Functions

 std_sfCmpExtension (filename, ext)
 Compare if a path has a given extension. More...
 
 std_sfConvertListPtoS (pFiles)
 Convert a list of read file references to a list of file references. More...
 
 std_sfConvertListPtoW (pFiles)
 Convert a list of read file references to a list of write file references. More...
 
 std_sfConvertListWtoP (wFiles)
 Convert a list of write file references to a list of read file references. More...
 
 std_sfConvertListWtoS (wFiles)
 Convert a list of write file references to a list of file references. More...
 
 std_sfGetExtension (path, with)
 Return the extension of a path name. More...
 
 std_sfGetFatherDirectory (rep, withSep)
 Return the father path directory in a path name. More...
 
 std_sfGetFirstPosSlash (s)
 Return the position of the first slash (/) in a path name. More...
 
 std_sfGetLastPosPoint (s)
 Return the position of the last point (.) in a path name. More...
 
 std_sfGetLastPosSlash (s)
 Return the position of the last slash (/) in a path name. More...
 
 std_sfGetPathFile (longfile, file)
 Get a file path and file name from a path. More...
 
 std_sfGetPathWithoutExtension (path)
 Return the path without the extension, if any. More...
 
 std_sfGetRootDirectory (rep, withSep)
 Return the root directory in a path name. More...
 
 std_sfGetTree (rep)
 Return the list of file names in some folders and its subfolders. More...
 
 std_sfGetTreeCb (lrep, cb)
 List all files and all subdirectories from a list of directories. For each directory, a function is called with the list of its files. More...
 
 std_sfPathFromRelativePath (relativePath, rootdir)
 Return the absolute path from a relative path. More...
 
 std_sfRelativePathFromPath (absolutePath, rootdir)
 Return the relative path from an absolute path. More...
 
 std_sfXor (pFile, wFile, szKey)
 To cipher/uncipher a file to another file by the XOR algorithm. More...
 

Detailed Description

Package to load : lib/std/systemfiles.pkg

Dependancies :

Function Documentation

std_sfGetTree ( rep  )

Return the list of file names in some folders and its subfolders.

Remarks
REQUIRED : lib/std/list.pkg is required. You must load it before use this function.
NOTE : this function can take a long time if the depth of the tree is important.

Prototype: fun [[S r1]] [S r1]

Parameters
[Sr1] : a list of folder (e.g. "lib" :: "locked/lib" :: nil)
Returns
[S r1] : a list of file names
std_sfGetTreeCb ( lrep  ,
cb   
)

List all files and all subdirectories from a list of directories. For each directory, a function is called with the list of its files.

Remarks
NOTE : this function can take a long time if the depth of the tree is important.

Prototype: fun [[S r1] fun [S [S r1]] u0] I

Parameters
[Sr1] : a list of directories (e.g. "lib" :: "locked/lib" :: nil)
fun[S [S r1]] u0 : function to call for each directory read. These arguments are :
  • the pathname of the current directory
  • the list of files in this directory
Returns
I : the number of found items
std_sfGetLastPosSlash ( )

Return the position of the last slash (/) in a path name.

Prototype: fun [S] I

Parameters
S: a path name
Returns
I : this position or nil if not found
std_sfGetFirstPosSlash ( )

Return the position of the first slash (/) in a path name.

Prototype: fun [S] I

Parameters
S: a path name
Returns
I : this position or nil if not found
std_sfGetLastPosPoint ( )

Return the position of the last point (.) in a path name.

Prototype: fun [S] I

Parameters
S: a path name
Returns
I : this position or nil if not found
std_sfGetFatherDirectory ( rep  ,
withSep   
)

Return the father path directory in a path name.

Prototype: fun [S I] S

Parameters
S: a pathname
I: a flag : 1 to add a slash at the end, else 0
Returns
S : the father directory
std_sfGetRootDirectory ( rep  ,
withSep   
)

Return the root directory in a path name.

Prototype: fun [S I] S

Parameters
S: a pathname
I: a flag : 1 to add a slash at the end, else 0
Returns
S : the root directory
std_sfGetPathWithoutExtension ( path  )

Return the path without the extension, if any.

Prototype: fun [S] S

Parameters
S: a pathname
Returns
S : the path without extension
std_sfGetExtension ( path  ,
with   
)

Return the extension of a path name.

Prototype: fun [S I] S

Parameters
S: a pathname
I: a flag : 1 to add a . at the begin, else 0
Returns
S : the extension or nil if no extension found
std_sfCmpExtension ( filename  ,
ext   
)

Compare if a path has a given extension.

Prototype: fun [S S] I

Parameters
S: a pathname
S: an extension, such as "pkg" or "png"
Returns
S : 1 if equal, nil if no extension found, 0 if not equal
std_sfGetPathFile ( longfile  ,
file   
)

Get a file path and file name from a path.

Prototype: fun [S S] [S S]

Parameters
S: the path
S: should set to nil
Returns
[S S] : the path and the filename
std_sfPathFromRelativePath ( relativePath  ,
rootdir   
)

Return the absolute path from a relative path.

let "./std/systemfiles.pkg" -> relative in
let "lib" -> rootdir in
_fooS std_sfPathFromRelativePath relative rootdir;  // lib/std/systemfiles.pkg
Remarks
REQUIRED : lib/std/string.pkg is required to use this function

Prototype: fun [S S] [S S]

Parameters
S: the relative path
S: the root directory
Returns
S : the absolute path
std_sfRelativePathFromPath ( absolutePath  ,
rootdir   
)

Return the relative path from an absolute path.

let "lib/std/systemfiles.pkg" -> absolute in
let "lib" -> rootdir in
_fooS std_sfRelativePathFromPath absolute rootdir;  // ./std/systemfiles.pkg
Remarks
REQUIRED : lib/std/string.pkg is required to use this function

Prototype: fun [S S] [S S]

Parameters
S: the absolute path
S: the root directory
Returns
S : the relative path
std_sfConvertListPtoS ( pFiles  )

Convert a list of read file references to a list of file references.

Prototype: fun [[P r1]] [S r1]

Parameters
[Pr1] : a list of read file references
Returns
[S r1] : the list of path file
std_sfConvertListWtoS ( wFiles  )

Convert a list of write file references to a list of file references.

Prototype: fun [[W r1]] [S r1]

Parameters
[Wr1] : a list of write file references
Returns
[S r1] : the list of path file
std_sfConvertListWtoP ( wFiles  )

Convert a list of write file references to a list of read file references.

Prototype: fun [[W r1]] [P r1]

Parameters
[Wr1] : a list of write file references
Returns
[P r1] : the list of read file references
std_sfConvertListPtoW ( pFiles  )

Convert a list of read file references to a list of write file references.

Prototype: fun [[P r1]] [W r1]

Parameters
[Pr1] : a list of read file references
Returns
[W r1] : the list of write file references
std_sfXor ( pFile  ,
wFile  ,
szKey   
)

To cipher/uncipher a file to another file by the XOR algorithm.

The same function ciphers and unciphers the initial file if the same key is given.

This algorithm is simple but not secure for critical data.

Prototype: fun [P W S] I

Parameters
P: a read file references. This is the file to cipher/uncipher. This file isn't loaded in Scol memory.
W: a write file references. This is the ciphering output.
S: the key to cipher/uncipher. Its length mist be >= at 1.
Returns
I : 0 or nil if an argument is bas.
Remarks
The output file is NOT overwritten. If it already exists, the output will be appended.
Input and output files should be DIFFERENT.
See also
std_szXor (in lib/std/string.pkg) for a string