jsish
Files
Not logged in

Overview

Jsi provides several groups of file-system related functions:

Note that when running in a Safe Interp, many of the above may be limited or disabled.


Channel

A Channel object can be created for reading and/or writing individual files. Generally an object is instantiated to open the file and then read/write operations are performed.

var f = new Channel('tests/filetest.txt');
if (!f) 
    puts('Can not open tests/filetest.txt');
else {
    while((n = f.gets())!=undefined) {
        puts(n);
    }
}

For more details see Reference.


File

The File sub-methods are used for accessing various attributes and information on files where just basic IO is not necessarily the goal.

File.mkdir('XX1');
File.mkdir('XX1/AA');
File.mkdir('XX1/BB');
File.rename('XX1/BB','XX1/CC.txt');
puts(File.glob(null,'XX1').sort());
puts(File.dirname('XX1/AA'));
puts(File.rootname('XX1/CC.txt'));
puts(File.tail('XX1/CC.txt'));
puts(File.type('XX1/CC.txt'));
puts(File.extension('XX1/CC.txt'));
//puts(File.realpath('XX1/CC.txt'));
puts(File.writable('XX1/CC.txt'));
puts(File.readable('XX1/CC.txt'));
puts(File.exists('XX1/CC.txt'));
puts(File.isdir('XX1/CC.txt'));
puts(File.isfile('XX1/CC.txt'));
File.remove('XX1',true);

Output is:

[ "AA", "CC.txt" ]
XX1
XX1/CC
CC.txt
directory
.txt
true
true
true
true
false
file

glob

The File glob method returns an array of matching files according to the rules:

File.glob();
File.glob("*.c");
File.glob(/^jsi.*\.c$/);
File.glob('*','tests');
File.glob('*.js',{dir:'tests', recurse:true});

The following options are available for File.glob:

Option Type Description Default
dirVALUEDirectory.
maxDepthINTMax depth to recurse to.
dirfuncFUNCReturns true to recurse into dir.
funcFUNCFunction that returns true to keep.
maxINTMax results to return.
notypesVALUEFile types to exclude, one or more of chars 'fdlpsbc' for file, directory, link, etc.
prefixSTRKEYString prefix to add to each file in list.
recurseBOOLRecurse into directories.
tailsBOOLReturn only the tails.
typesVALUEFile types to include, one or more of chars 'fdlpsbc' for file, directory, link, etc.

For more details see Reference.


exec

function exec(val:string, options:null|string|object=void)

The exec() command is used to execute operating system commands:

var a = exec('ls -d /tmp');

A second argument may be given with the following options:

Option Type Description Default
bgBOOLRun command in background using system() and return OS code.
inputStrSTRINGUse string as input and return OS code.
noErrorBOOLSuppress OS errors.
noTrimBOOLDo not trim trailing whitespace from output.
retAllBOOLReturn the OS return code and data as an object.
retCodeBOOLReturn only the OS return code.

The first argument is treated as follows:

In C, when the bg option is true, system() is called, otherwise popen() is used.

For more details see exec in the System Reference and the exec test.


console

log

Same as puts, except prints arguments to stderr.

Each argument is quoted (unlike the builtin string concatenation). If called with 0 or 1 argument, a newline is output, otherwise stderr is flushed.

puts

Same as console.log, except prints arguments to stdout. Also, available in System (and therefore the toplevel).

The puts method outputs a string to stdout. With 1 or 0 arguments a newline is appended.

puts("Hello World");
puts("Hello"," World\n");

Scripts also used in web browsers can add the following for compatibility:

if (puts === undefined)
    var puts = console.log.bind(console);

input

User input can be obtained using console.input():

puts("Enter your name: ", "");
var str = console.input();

args

Program arguments are available using console.args:

for (var i in console.args) {
   puts(console.args[i]);
}

For more details see Reference.


Zvfs

Jsi uses Zvfs for reading and writing zip archives. Zvfs stands for Zip Virtual File System.

For more details see Zvfs.


source

Include files of javascript inline.

For more details see source.