Subsections of Files

EVENTS

File change event

[on] (file|dir[ectory]) creation[s] (at|for) [[the] (file[s]|dir[ector(y|ies)]|paths)] %strings%
[on] (file|dir[ectory]) modify[ication][s] (at|for) [[the] (file[s]|dir[ector(y|ies)]|paths)] %strings%
[on] (file|dir[ectory]) deletion[s] (at|for) [[the] (file[s]|dir[ector(y|ies)]|paths)] %strings%
[on] (file|dir[ectory]) overflow[s] (at|for) [[the] (file[s]|dir[ector(y|ies)]|paths)] %strings%
[on] every (file|dir[ectory]) change[s] (at|for) [[the] (file[s]|dir[ector(y|ies)]|paths)] %strings%

EXPRESSIONS

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)]) [path] %strings%
set {_file} to file "eula.txt"

Get an absolute path

Absolute means the path starts from the root of the file system.

absolute path of %path%
%path%'s absolute path
set {_file} to absolute path of file "eula.txt"

Get all files inside a directory

You can do this recursively, getting files in the directory and all internal directories.

[all] files in %path%
loop all files in dir "plugins/":
  broadcast "%loop-value%"

Get the text content of a file

Can be changed.

content[s] of %path%
%path%'s content[s]
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

Can be changed.

name of %path%
%path%'s name
loop all files in dir "plugins/":
  broadcast name of file loop-value

Read a line or 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 or folder is located

Can be changed.

parent of %path%
%path%'s parent
set {_file} to parent of file "eula.txt"

Get file size in bytes

size of %path%
%path%'s size

Get the last access date of a file

last access time of %path%
%path%'s last access time

Get the last modified date of a file

last modified time of %path%
%path%'s last modified time

Get file creation date

creation time of %path%
%path%'s creation time

Get file extension

extension of %path%
%path%'s extension

Disk space info

total space of %path%
usable space of %path%

CONDITIONS

Checking if a path exists

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

Checking if a path is a directory

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

Checking if a path is a file

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

Checking if a path is empty

%path% is[(n't| not)] empty

Checking if a path is executable

%path% is[(n't| not)] executable

Checking if a path is hidden

%path% is[(n't| not)] hidden

Checking if a path is readable

%path% is[(n't| not)] readable

Checking if a path is a system file

%path% is[(n't| not)] [a] system file

Checking if a path is writable

%path% is[(n't| not)] writable

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%
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

[(async/sync)] create %path% [with content %strings%]
create file "eula.txt" with content "eula=true"

Delete a file or directory

[(async/sync)] delete %path%
delete file "plugins/Skript-2.11.1.jar"

Move a file or directory

[(async/sync)] move %paths% to %path%
move file "plugins" to file "disabled_plugins"

Rename a file or directory

[(async/sync)] rename %path% to %string%
rename file "plugins/Skript/scripts/mycoolscript.sk" to "-mycoolscript.sk"

Unpack the zip archive

[(async/sync)] unzip %path% to %path%
unzip file "myarchive.zip" to file "./"

Create a zip archive

[(async/sync)] zip %path% to %path%
zip file "world/" to file "backupworld.zip"

Download a file

[(async/sync)] download file from [url] %string% (and store it in|to) %path%
async download file from "https://github.com/SkriptLang/Skript/releases/download/2.11.1/Skript-2.11.1.jar" to "plugins/Skript-2.11.1-FILE.jar"

The code in this example will download Skript 2.11.1 to the /plugins/ directory with Skript-2.11.1-FILE.jar as the name of the file.