VFS global object.
A VFS global object is created for you and only this object can exist in the application. It is named VFS and is globally accessible.
none.
global name space.
ECMerge 2.1
The VFS object let you realize a few basic operations on files and folders currently. Files and folders are pointed to by URL objects.
Property | Description |
kRead | Integer. Used to indicate that a file is open for reading only |
kWrite | Integer. Used to indicate that a file is open for writing only |
kReadWrite | Integer. Used to indicate that a file is open for both reading and wirting |
kAppend | Integer. Used to indicate that a file is open to write at end |
kCreateAlways | Integer. Used to indicate that a file is always opened empty, ignoring its presence and/or old content |
kCreateNew | Integer. Used to indicate that a file is only added |
kOpenExisting | Integer. Used to indicate that a file is only opened (i.e. not created) |
kOpenAlways | Integer. Used to indicate that a file is opened if it is there, created if it was not |
kTruncateExisting | Integer. Used to indicate that a file is only opened, but emptied at once |
kShareRead | Integer. Used to indicate that a file is open, allowing others to read at the same time |
kShareWrite | Integer. Used to indicate that a file is open, allowing others to write at the same time |
kShareAll | Integer. Used to indicate that a file is open ,allowing all accesses |
kShareNone | Integer. Used to indicate that a file is open, but none else should access the file |
kTemporary | Integer. Used to indicate that a file is open as a temporary file |
kAutoAbort | Integer. Used to indicate that a file is open, but it should be deleted unless a validation occurs successfuly |
kFileAttrReadWrite | Ineger. Used to indicate that the item can be written to (by current user on Unix, by any user with appropriate rights else) |
kFileAttrHidden | Integer. Used to indicate that a file as the hidden attribute |
kFileAttrSystem | Integer. Used to indicate that a file as the system attribute |
kFileAttrDirectory | Integer. Used to indicate that the item is a directory |
kFileAttrArchive | Integer. Used to indicate that a file as the archive attribute |
kFileAttrNormal | Integer. Used to indicate a normal file |
kFileAttrTemporary | Integer. Used to indicate that a file as the temporary attribute |
kFileAttrCompressed | Integer. Used to indicate that a file/directory is compressed |
kFileAttrEncrypted | Integer. Used to indicate that the file/directory is encrypted |
kFileAttrSymLink | Integer. Used to indicate that the file/directory is a symbolic link. |
kFileAttrUnixModesMultiplier | Integer. Multiply Unix modes by this number to represent them in a attrib bit-mask. |
attrib
dir
get_temporary_dir_url
get_temporary_file_name
get_temporary_file_url
load_text
save_text
set_dates
stat
see functions samples.
URL object.
function attrib ( url, attributes_to_set, attributes_values )
url.
URL
object. URL toward the directory to list
attributes_to_set. UInt32. Bit mask of files
attributes to set choosen from kFilesAttr??? values.
attributes_values. UInt32. Bit mask of files
attributes values choosen from
kFilesAttr??? values.
VFS object.
ECMerge 2.1
Modifies the attributes of a file. Attributes which are not present in the parameter attributes_to_set are not affected by attrib execution.
Mark a file as read-write:
VFS.attrib ("c:\\myfile.txt", VFS.kFileAttrReadWrite, VFS.kFileAttrReadWrite);
URL object, VFS object, VFS.Metadata object
function dir ( url, re )
returns an Array of
VFS.Metadata
objects.
url.
URL
object. URL toward the directory to list
re. RegExp object. Only entries matching this regular
expression are returned. If omitted, all entires are
returned
VFS object.
ECMerge 2.1
Lists the directory designed by url and returns the entries as an Array of metadata.
Dumps as XML the metadata of all the elements under the root of the file system:
var metadata_array = VFS.dir ("/");
log ( metadata_array.join ( ) );
URL object, VFS object, VFS.Metadata object
function get_temporary_dir_url ( with_ext )
returns a String
with_ext. If defined, the directory's name will end with this string
VFS object.
ECMerge 2.2
Returns the name for a temporary file. Usually an empty file is created with this name during the execution of this call, to avoid another call returning the same value.
Makes a temporay directory and save a file called myfile.txt within:
var my_temp_dir = VFS.get_temporary_dir_url ();
VFS.save_text (my_temp_dir.compose('myfile.txt'), 'the
file content');
get_temporary_file_name method, get_ temporary_file_url method, VFS object
function get_temporary_file_name ( )
returns a String
none.
VFS object.
ECMerge 2.1
Deprecated. Supersedeed by
get_temporary_file_url
and
get_temporary_dir_url
since ECMerge 2.2
Returns the name for a temporary file. Usually an
empty file is created with this name during the execution
of this call, to avoid another call returning the same value.
NB: This method is deprecated
because it had to let the empty file there to avoid
synchronization problems, but the empty file was never deleted.
Use
get_temporary_file_url
and
get_temporary_dir_url
instead.
Prints 10 different temporary file names:
for (var idxtfn=0; idxtfn<10; ++idxtfn)
log ( VFS.get_temporary_file_name ()
);
VFS object
function get_temporary_file_url ( with_ext )
returns a String
with_ext. If defined, the file's name will end with this string
VFS object.
ECMerge 2.2
Returns the name for a temporary file. Usually an empty file is created with this name during the execution of this call, to avoid another call returning the same value.
Prints 10 different temporary file names with the '.txt' extension:
for (var idxtfn=0; idxtfn<10; ++idxtfn)
log ( VFS.get_temporary_file_url
('.txt') );
get_temporary_file_name method, get_temporary_dir_url method, VFS object
function load_text (url, encoding, detect, at_most)
returns a String
url.
URL
object. URL pointing to the text file to read.
encoding. Encoding string. Encoding to use (see
'detect'). If undefined or omitted, load_text uses default
system encoding.
detect. Boolean. True when signatures detection is
enabled (currently Unicode signatures), hence encoding is a
'default'. False to ignore signatures, therefore, encoding is
then always used. If undefined or omitted, true is assumed.
at_most. Integer. Number of bytes which you accept to
read from the file. If undefined or omitted, the whole file is
read.
VFS object.
ECMerge 2.1
Reads a text file and returns its content as a string.
Displays a message with the content of a file:
alert ( VFS.load_text ( "/etc/hosts" ) );
VFS object
function save_text ( url, text, encoding, save_signature, creation_flags)
url.
URL
object. URL pointing where to save the text.
text. String. Text to save
encoding. Encoding string. Encoding to use to save the
text. If undefined or omitted, default system encoding is used.
save_signature. Boolean. True when the appropriate
signature for
encoding should be written. If undefined or omitted,
true is assumed.
creation_flags. Integer. A bitwise-OR of VFS.k???
constants. If undefined or omitted,
VFS.kCreateNew|VFS.kReadWrite|VFS.kShareNone is
assumed.
VFS object.
ECMerge 2.1
Saves a text to a URL location, in a given encoding.
Saves a text file:
var text = "hello world!";
VFS.save_text ("/tmp/mytest.txt", text, "UTF-8", true,
VFS.kCreateAlways|VFS.kWrite);
function set_dates ( url, last_access, last_update, creation)
url.
URL
object. URL pointing to the file.
last_access. Date. Last access date to item. If
undefined or omitted, this date is not set for the file
last_update. Date. Date of last modification of the file.
If undefined or omitted, this date is not set for the file
creation. Date. Date of creation of the file. If
undefined or omitted, this date is not set for the file
VFS object.
ECMerge 2.2
Set the dates for a file. Most file system supports
three dates: the creation date, the last modification date and
last access date, this function let you set these dates with
arbitrary values.
Note that some file systems store only a "last_update"
date. Each file system store dates with a specific
precision, some use 2-seconds precision (FAT), some use real
tight precision (below the microsecond, NTFS). JavaScript Date
objects have a built-in precision at the millisecond, you might
thus be unable to repesent the dates of NTFS with
exactness.
Set all the dates to current date for imaginary file "/tmp/mytest.txt" :
var my_date = new Date();
VFS.set_dates ("/tmp/mytest.txt", my_date, my_date,
my_date);
Implements the famous "touch" function in ECMerge :
function touch (url) {
VFS.set_dates (url, undefined, new
Date());
}
function stat ( url )
returns a VFS.Metadata object
url. URL object. URL pointing to the file.
VFS object.
ECMerge 2.2.109
Returns the metadata for a single item pointed to by a URL.
Displays the last update time for a FTP file:
alert (VFS.stat("ftp://myserver.domain.com/a-file.txt"));