For all files under /some/folder
, if the file is greater than 50 mb, move it to /other/folder
:
someFolder = '/some/folder' # paths are either absolute or relative to the location of the script file
otherFolder = '/other/folder'
filesToCheck[] = someFolder -> '*' # wildcards allow creating a list with all files that match pattern
for (file in filesToCheck[]) {
if (file.size > 50 MB) { # can be 'B', 'KB', 'MB', 'GB', 'TB', 'PB'
move file to otherFolder
}
}
Reference a folder:
myFolder = '/path/to/some/folder' # stores a reference to folder in variable myFolder
Reference a file
myFile = '/path/to/some/file.ext' # stores a reference to file.ext in variable myfile
Reference a file relative to a folder
myFile = myFolder -> 'file.ext' # stores a reference to myFolder/file.ext
Reference multiple files and folders
subFilesAndFolders[] = '/path/to/some/parent/*' # subFilesAndFolders[] is a list of all files and folders under /parent
# Alternatively
parent = '/path/to/some/parent'
subFilesAndFolders[] = parent -> '*' # subFilesAndFolders[] is a list of all files and folders under /parent
myFile.name # returns file name
myFile.size # returns file size in bytes
myFile.created # returns UNIX timestamp of creation
myFile.modified # returns UNIX timestamp of last modification
myFile.extension # returns the extension as a string. eg. 'exe'. '' for folders.
myFile.parent # returns reference to parent folder
myFile.isFile # boolean value. True if myFile is a file.
myFile.isDirectory # boolean value. True if myFile is a directory/folder
if (some condition) {
# enters block on condition being true
}
if (some condition) {
# enters block on condition being true
# action here
if (some other condition) {
# enters block on second condition being true
}
}
if (some condition and some condition) {
}
OR
if ((some condition) AND (some other condition)) { # AND, OR, NOT
# enters block on both conditions being true
}
Action format:
<command> <target> (to | into <destination>)?
All commands:
copy
move
delete
rename
create
compress
Copy a file:
copy someFile to otherFolder # special cases: overwrite?
Delete a file:
delete someFile
Create a folder:
myFolder = '/some/folder'
create myFolder
# Create myFile throws error. Cannot create files.
myFolder = '/some/folder'
otherFolder = '/some/otherFolder'
create myFolder
copy myFolder to otherFolder
if (file.size > 50 MB) { # can be 'B', 'KB', 'MB', 'GB', 'TB', 'PB'
move file to otherFolder
}
PROGRAM ::= STATEMENT*
STATEMENT ::= ACTION | IF_STATEMENT | FOR_LOOP | DECLARATION | RETURN
ACTION ::= COMMAND FILE_VARIABLE (PREPOSITION ACTION_DESTINATION)?
IF_STATEMENT ::= 'if(' CONDITION ') {' PROGRAM '}' ('else' '{' PROGRAM '}')?
FOR_LOOP ::= 'for(' ITERATOR ') {' PROGRAM '}'
DECLARATION ::= DIRECT_DECLARATION | REFERENCE_DECLARATION
RETURN ::= 'return'
COMMAND ::= 'copy' | 'move' | 'delete' | 'rename' | 'create' | 'compress'
PREPOSITION ::= 'to'
ACTION_DESTINATION ::= [FILE_VARIABLE | ('"' FILENAME '"')]
FILE_VARIABLE ::= [a-zA-Z0-9]+
LIST_VARIABLE ::= FILE_VARIABLE '[]'
VARIABLE ::= FILE_VARIABLE | LIST_VARIABLE
CONDITION ::= OR_CONDITION
OR_CONDITION ::= AND_CONDITION ('OR' AND_CONDITION)*
AND_CONDITION ::= NEGATION ('AND' NEGATION)*
NEGATION ::= (NEGATION_OPERATOR NEGATION) | BOOLEAN
BOOLEAN ::= 'True' | 'False' | COMPARISON | CONDITION | '(' BOOLEAN ')'
COMPARISON ::= TERM COMPARISON_OPERATOR TERM
TERM ::= ATTRIBUTE | (NUMBER (UNIT)?) | STRING | BOOLEAN
ATTRIBUTE ::= FILE_VARIABLE '.' ATTRIBUTE_NAME
ATTRIBUTE_NAME ::= 'name' | 'size' | 'created' | 'modified' | 'extension' | 'parent' | 'isFile' | 'isDirectory'
NUMBER ::= [0-9]+
UNIT :: = 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB'
NEGATION_OPERATOR ::= 'NOT' | '!'
COMPARISON_OPERATOR := '<' | '>' | '==' | '>=' | '<=' | '!='
ITERATOR ::= FILE_VARIABLE 'in' LIST_VARIABLE
DIRECT_DECLARATION ::= VARIABLE '=' PATH
REFERENCE_DECLARATION ::= VARIABLE '=' VARIABLE
PATH ::= ABSOLUTE_PATH | RELATIVE_PATH | VARIABLE '->' PATH
ABSOLUTE_PATH ::= DRIVENAME RELATIVE_PATH?
RELATIVE_PATH ::= FILENAME | (FILENAME '\' RELATIVE_PATH)
DRIVENAME ::= [A-Z] ':\'
FILENAME ::= [\*0-9a-zA-Z\_\-\.\s]+
These are rules that check for syntactically correct but semantically wrong inputs.
These rules should be checked in addition to checking that the program meets the syntax above. Syntax rules are not repeated below.
Validation rules are static (i.e. does not check if files/folders exist) and are checked prior to evaluation
- Variables declared before usage for all statements
- Each statement is independently valid
- Command is valid
- File variable is valid
- If Command is one of 'copy' or 'move' then destination is a file variable
- If Command is 'rename' then destination is a file name
- If Command is 'delete', 'create' or 'compress' then no preposition and destination are given
- Condition is valid
- First Program is valid. Second Program is null or valid.
- Iterator is valid
- Program is valid
- Both terms should evaluate to the same type
- If the operator is not '==' or '!=', then the terms must evaluate to numbers
- File variable must not have been declared before
- If path contains wildcard ('*') then variable must be list variable
- Variable on right must have been declared before
- In the VARIABLE '->' PATH case, the variable must have been declared before