Either Folder


File system functions come in two forms. Older functions were written as two distinct functions names, only the prefix changed; Where fexists() operates on files in the secure data directory (often named mivadata) and sexists() operates on the web site directory (often called html or httpdocs).

These functions are grouped under Data Folder and Script Folder respectively.

Newer file systems functions contain an additional "location" parameter where location is either 'data' or 'script'. For example file_read( path, location, input_data var ). These functions are grouped together under Either Folder.

Name -- Syntax / Description
dir
dir( path, location, entries var )
Reads a directory list in path.
Returns the number of files found or 0 (zero) if none are found. The parameter entries returns an array of file names found.
  • path = The path to a directory relative to the location
  • location = "data" or "script"
  • entries = array of resultant file names
file_append
file_append( path, location, outputdata var )
Appends data to the end of the file in path.
Returns length of outputdata or -1 on error. file_append() will not create a file, but return -1 if the file does not exist.
  • path = fully qualified path to the file
  • location = location of the output file - 'data' or 'script'
  • outputdata = string variable containing the data to append
file_create
file_create( path, location, outputdata var )
Creates and appends data to the file in path.
Returns length of outputdata or -1 on error. file_create() will not append to an existing file, but return -1 if the file exists.
  • path = fully qualified path to the file
  • location = location of the output file - 'data' or 'script'
  • outputdata = string variable containing the data to append
file_read
file_read( path, location, inputdata var )
Reads a file.
Returns length of inputdata or -1 on error or file does not exist.
  • path = fully qualified path to the file
  • location = location of the input file - 'data' or 'script'
  • inputdata = string variable containing the data read
file_read_bytes
file_read_bytes( path, location, offset, length, data )
Reads a portion of the file specified by "path" and "location" into "data". Returns the number of bytes read, which may be less than "length", if an attempt was made to read past the end of the file, or -1 on error.
Returns the number of bytes read from the file. The file data is returned in "data".
  • path = The name or filepath of the file to open relative to the directory specified by "location"
  • location = One of "script" or "data"
  • offset = The zero-based offset at which to begin reading
  • length = The number of bytes to read. If < 0, the entire file after "offset" is read.
  • data = The variable in which to store the file data
file_touch
file_touch( file, location )
Updates the modification time of the specified file.
Return value: 0 on success, -1 on failure.
  • file = File name.
  • location = File location. "script" or "data", defaulting to "data" if any other value.
miva_lockfile
miva_lockfile( path, location )
Creates and locks a lockfile. Similar to the behavior of MvLOCKFILE without the closing /MvLOCKFILE behavior. It also creates the exact filename, rather than appending ".lck" to the filename as MvLOCKFILE does.
Returns 1 if sucessful, -1 if fails
  • path = fully qualified path to the file
  • location = location of the file - 'data' or 'script'
  • Use fdelete() or sdelete() to delete the lockfile.
wdownload
wdownload( url, filepath, location, callback, callbackdata var )
Downloads and stores a file from a URL. Acts as a front end to wget()
Returns -1 if fails, returns the server response code: Possible examples 200 = success, 301 = moved, 404 = not found.
  • url = file to retrieve
  • filepath = where destination file should be stored
  • location = destination 'data' or 'script'.callback_fn = the name of a callback function in current Miva Script file
  • callback_fn( size, total, data var ): a user defined user function that returns 1 to continue, 0 to abort.
  • callbackdata var = ???? Unknow please clarify
wget
wget( url, filepath, location )
Downloads and stores a file from a URL. Note: If an error occurs, the error message will be stored instead.
Returns -1 if fails, returns the server response code: Possible examples 200 = success, 301 = moved, 404 = not found.
  • url = file to retrieve
  • filepath = where destination file should be stored
  • location = destination 'data' or 'script'.
file_overwrite
file_overwrite( path, location, data var )
Replaces the file in path if it exists. If will not create the file if it does not exist.
Returns the length of data written or -1 on error
  • path = fully qualified path to the file
  • location = 'data' or 'script'
  • data = string variable containing the data to write
User Annotations: filesystem-both