Top Documents Download Gallery Repository
Are you looking for a Software Engineer? Check Here

20fs Module

The fs module provides measures to access and modify information in file systems. This is a built-in module, so you can use it without being imported.

20.1Module Function

fs.chdir(pathname:string) {block?}
Changes the current working directory to pathname.

The block would be evaluated if specified, and the working directory would be changed only during that evaluation period.

fs.chmod(mode, pathname:string):map:void:[follow_link]
Changes the access mode of a file specified by pathname.

There are two formats to specify the mode: one is by a number, and another in a string.

When specified in a number, following bits are associated with access permissions:

When set to one, each permission is validated.

When specified in a string, it accepts a permission directive in a format of following regular expression


It starts with characters that represent target which permissions are modified as described below:

Then, follows an operation:

At last, permission attributes are specified as below:

If the modification target is a link file, each platform would have different result:

fs.copy(src:string, dst:string):map:void:[overwrite]
Copies a file.

An argument src needs to specify a path name of a file that is to be copied while dst can specify a path name of either a file or a directory. If dst is a directory, the file would be copied into that. Otherwise, it would create a copy of src that has a name specified by dst.

If a destination file already exists, an error occurs. Specifying an attribute :overwrite would overwrite an existing one.

fs.cpdir(src:string, dst:string):map:void:[tree]
Copies a directory.

Arguments src and dst specify source directory and destination directory respectively. In default, sub directories are not copied.Specifying :tree attribute would copy all the sub directories in the source.

Returns the current working directory.

Creates a directory.

If pathname consists of multiple sub directories and some of them still doesn't exist, an error occurs. Specifying :tree attribute would create such directories.

Removes a file from the file system.

fs.rename(src:string, dst:string):map:void
Renames a file or directory.

Removes a directory.

If the directory contains sub directories, an error occurs. Specifying :tree attribute would delete such a directory.

20.2fs.stat Class

An instance of fs.stat class contains information about a file or directory on the file system, which includes its full path name, size, creation time and file attributes. A stream instance has a property named stat that is a fs.stat instance when it comes from a file or directory in a file system. You can also get the instance using fs.stat() function.


fs.stat(pathname:string) {block?}


A fs.stat instance has the following properties:

Property Type R/W Explanation
pathname string R
dirname string R
filename string R
size number R
uid number R
gid number R
atime datetime R
mtime datetime R
ctime datetime R
isdir boolean R
ischr boolean R
isblk boolean R
isreg boolean R
isfifo boolean R
islnk boolean R
issock boolean R

Copyright (C) 2011-2017 ypsitau