Module xFilesystem

Static methods for dealing with the file-system .

Functions

get_path_parts (file_path) split path into parts, seperated by slashes important - folders should end with a slash note: this is a virtual function which doesn't require I/O access
get_raw_filename (file_path) provided with a complete path, returns just the filename (no extension) note: this is a virtual function which doesn't require I/O access
is_root_folder (str) check if the given string indicates a root folder note: a root folder is considered "/" on unix-based systems, and on windows systems note: this is a virtual function which doesn't require I/O access
get_parent_directory (file_path) provided with a string, this method will find the parent folder note: returned string is using unix slashes note: this is a virtual function which doesn't require I/O access
copy_file (file_in, file_out) this will work for small files, but is not recommended on larger ones
ensure_unique_filename (file_path) if file already exist, return a name with (number) appended to it note: this is a virtual function which doesn't require I/O access
get_directories (file_path) break a string into directories note: this is a virtual function which doesn't require I/O access
makedir (file_path) create a whole folder structure in one go (unlike the standard os.mkdir, which is limited to a single folder)
rename (old_f, new_f) rename a file or folder
rmdir (folder_path) on non-posix systems (windows), you can't remove a folder which is not empty - this method will iterate through and delete all files/folders
validate_filename (file_path) make sure a file/folder name does not contain anything considered bad (such as special characters or preceding ./ dot-slash combinations)
unixslashes (file_path) convert windows-style paths to unix-style also: remove doubleslashes
sanitize_filename (file_path) remove illegal characters (similar to validate, but attempts to fix)
file_add_extension (file_path, extension) add file extension (if it hasn't already got it)
file_strip_extension (file_path, extension) remove file extension (if present and matching)
assert_string (str, str_name) so widely used it got it's own function
load_string (file_path) load string from disk
write_string_to_file (file_path, str) save string to disk
recurse (str_path, callback_fn, file_ext, level) iterate through folders, starting from the provided path


Functions

get_path_parts (file_path)
split path into parts, seperated by slashes important - folders should end with a slash note: this is a virtual function which doesn't require I/O access

Parameters:

  • file_path (string)

Returns:

  1. string, folder
  2. string, filename
  3. string, extension
get_raw_filename (file_path)
provided with a complete path, returns just the filename (no extension) note: this is a virtual function which doesn't require I/O access

Parameters:

  • file_path (string)

Returns:

    string or nil
is_root_folder (str)
check if the given string indicates a root folder note: a root folder is considered "/" on unix-based systems, and on windows systems note: this is a virtual function which doesn't require I/O access

Parameters:

  • str
get_parent_directory (file_path)
provided with a string, this method will find the parent folder note: returned string is using unix slashes note: this is a virtual function which doesn't require I/O access

Parameters:

  • file_path (string)

Returns:

  1. string or nil if failed
  2. int, error code
copy_file (file_in, file_out)
this will work for small files, but is not recommended on larger ones

Parameters:

  • file_in (string)
  • file_out (string)

Returns:

    boolean,string
ensure_unique_filename (file_path)
if file already exist, return a name with (number) appended to it note: this is a virtual function which doesn't require I/O access

Parameters:

  • file_path (string)
get_directories (file_path)
break a string into directories note: this is a virtual function which doesn't require I/O access

Parameters:

  • file_path (string)

Returns:

    table
makedir (file_path)
create a whole folder structure in one go (unlike the standard os.mkdir, which is limited to a single folder)

Parameters:

  • file_path (string)

Returns:

  1. bool, true when folder(s) were created
  2. string, error message when failed
rename (old_f, new_f)
rename a file or folder

Parameters:

  • old_f (string)
  • new_f

    (string) TODO @param options (table)

    "replace" - for existing files/folders
    "merge" - for existing folders
    
rmdir (folder_path)
on non-posix systems (windows), you can't remove a folder which is not empty - this method will iterate through and delete all files/folders

Parameters:

  • folder_path (string)

Returns:

  1. bool, true when folder was removed
  2. string, error message when failed
validate_filename (file_path)
make sure a file/folder name does not contain anything considered bad (such as special characters or preceding ./ dot-slash combinations)

Parameters:

  • file_path (string)

Returns:

    bool,string
unixslashes (file_path)
convert windows-style paths to unix-style also: remove doubleslashes

Parameters:

  • file_path (string)

Returns:

    string
sanitize_filename (file_path)
remove illegal characters (similar to validate, but attempts to fix)

Parameters:

  • file_path (string)

Returns:

    string
file_add_extension (file_path, extension)
add file extension (if it hasn't already got it)

Parameters:

  • file_path (string)
  • extension (string)

Returns:

    string
file_strip_extension (file_path, extension)
remove file extension (if present and matching)

Parameters:

  • file_path (string)
  • extension (string)

Returns:

    string
assert_string (str, str_name)
so widely used it got it's own function

Parameters:

  • str
  • str_name
load_string (file_path)
load string from disk

Parameters:

  • file_path
write_string_to_file (file_path, str)
save string to disk

Parameters:

  • file_path (string)
  • str (string)

Returns:

  1. bool, true when successful, false when not
  2. string, error message when failed
recurse (str_path, callback_fn, file_ext, level)
iterate through folders, starting from the provided path

Parameters:

  • str_path (string)
  • callback_fn (function) return false to stop recursion
  • file_ext (string)
  • level (int)
generated by LDoc 1.4.2