Files

This module allows you to perform operations with files.

Special thanks to the Olyno for creating an addon Skent . This module was developed due to the fact that at that moment he abandoned development, but now his addon has an option for asynchronous work with files. Part of the code was borrowed from the first version of his addon.

EXPRESSIONS
CONDITIONS
EFFECTS

Subsections of Files

EXPRESSIONS

In fact, you get either a real file, if there is one, or an abstract file that can then be created.

[the] (file[s]|dir[ector(y|ies)]) %strings%
set {_file} to file "eula.txt"

Get an absolute file

Absolute - that is, the one with the path starting from the root of the file system

absolute [(file|dir[ectory])] of %path%
%path%'s absolute [(file|dir[ectory])] 
set {_file} to absolute file of file "eula.txt"

Get all files inside a directory

It also allows you to do this recursively, getting files in the directory and in all internal directories

all [the] files and [all] [the] dir[ectorie]s (in|of|from) %path%
all [the] files (in|of|from) %path%
all [the] dir[ectorie]s (in|of|from) %path%
all [the] sub[(-| )]files and [all] [the] sub[(-| )]dir[ectorie]s (in|of|from) %path%
all [the] sub[(-| )]dir[ectorie]s (in|of|from) %path%
all [the] sub[(-| )]files (in|of|from) %path%
glob (files|dir[ectorie]s) %string% (in|of|from) %path%
loop all files from file "plugins/":
  broadcast "%loop-value%"

Get the text content of the file

[the] content of %path%
[the] %path%'s content
set {_file} to content of file "eula.txt"
replace all "false" with "true" in {_file}
set content of file "eula.txt" to {_file}

Get the name of a file or directory

[the] (file|dir[ectory])name of %path%
[the] %path%'s (file|dir[ectory])name
loop all files from file "plugins/":
  broadcast filename of loop-value

Read a line/lines of a file or change them

[the] line %number% (from|of|in) %path%
[all] [the] lines (from|of|in) %path%
set line 1 of file "eula.txt" to "eula=true"

Get the directory where the file/folder is located

parent [(file|dir[ectory])] of %path%
%path%'s parent [(file|dir[ectory])]
set {_file} to parent of file "eula.txt"

Get file size in bytes

file size of %path%
%path%'s file size

Get the last access date of a file

[last] access (date|time) of %path%
%path%'s [last] access (date|time)

Get the last modified date of a file

[last] modified (date|time) of %path%
%path%'s [last] modified (date|time)

Get file creation date

create[d] (date|time) of %path%
%path%'s create[d] (date|time)

CONDITIONS

Checking the file for its actual existence

%path% (is|does)[(n't| not)] exist[s]
if file "eula.txt" is exists:
  broadcast "Yea, file eula.txt is exists"

Checking that the file is a directory

%path% is[(n't| not)] dir[ectory]
if file "eula.txt" is not directory:
  broadcast "Yea, file eula.txt is not directory, it is regular file"

Checking that the file is a file

%path% is[(n't| not)] file
if file "eula.txt" is file:
  broadcast "Yea, file eula.txt is regular file"

EFFECTS

Copy a file or directory

It also allows you to specify a parameter for overwriting if the file already exists

copy %path% to %path% [with (replac|overwrit)(e|ing)]
copy file "plugins/Skcrew.jar" to file "./"

Create a simple file

It also allows you to specify the text content of the file being created

create %paths% [with [(text|string|content)] %strings%]
create file "eula.txt" with content "eula=true"

Delete a file or directory

delete %paths%
delete file "plugins/Skcrew.jar"

Move a file or directory

It also allows you to specify a parameter for overwriting if the file already exists

move %paths% to %path% [with (overwrit|replac)(e|ing)]
move file "plugins" to file "disabled_plugins"

Rename a file or directory

It also allows you to specify a parameter for overwriting if the file already exists

rename %paths% to %string% [with (overwrit|replac)(e|ing)]
rename file "plugins/Skript/scripts/mycoolscript.sk" to "-mycoolscript.sk"

Unpack the zip archive

It also allows you to specify a parameter for overwriting if the file already exists

unzip %path% to %path% [with (overwrit|replac)(e|ing)]
unzip file "myarchive.zip" to file "./"

Create a zip archive

It also allows you to specify a parameter for overwriting if the file already exists

zip %paths% to %path% [with (overwrit|replac)(e|ing)]
zip file "world/" to file "backupworld.zip"