filemanager.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. Function: file_move(file[], destination[]);
  3. Description: Moves a specified file to the specified destination.
  4. Params:
  5. file[] - The name of the file to be moved.
  6. destination[] - The destination to move the file to, including the file name.
  7. Returns: True if success, false if not.
  8. */
  9. native file_move(file[], destination[]);
  10. /*
  11. Function: file_copy(file[], destination[]);
  12. Description: Copies a specified file to the specified destination.
  13. Params:
  14. file[] - The name of the file to be copied.
  15. destination[] - The new destination of the file to be copied to, including the file name.
  16. Returns: True if success, false if not.
  17. */
  18. native file_copy(file[], destination[]);
  19. /*
  20. Function: file_delete(file[]);
  21. Description: Deletes a specified file.
  22. Params:
  23. file[] - The name of the file to be deleted.
  24. Returns: True if success, false if not.
  25. */
  26. native file_delete(file[]);
  27. /*
  28. Function: file_create(file[]);
  29. Description: Creates a specified file.
  30. Params:
  31. file[] - The name of the file to be created.
  32. Returns: True if success, false if not.
  33. */
  34. native file_create(file[]);
  35. /*
  36. Function: file_write(file[], text[], mode[] = "a");
  37. Description: Writes a string to a specified file with the specified mode.
  38. Params:
  39. file[] - The name of the file to be written to.
  40. text[] - The string to write to the file.
  41. mode[] - The mode to use (doesn't need to be specified, will append by default, can be set otherwise)
  42. Returns: True if success, false if not.
  43. */
  44. native file_write(file[], text[], mode[] = "a");
  45. /*
  46. Function: file_read(file[], storage[], size = sizeof(storage));
  47. Description: Reads the entire file into a specified string.
  48. Params:
  49. file[] - The name of the file to be read into memory.
  50. storage[] - The array to store the read data in.
  51. size[] - The size of the storage array (used to prevent buffer overflows), no reason for you to specify it in practice.
  52. Returns: True if success, false if not.
  53. */
  54. native file_read(file[], storage[], size = sizeof(storage));
  55. /*
  56. Function: file_log();
  57. Description: Will enable filemanager logging (prints information about file operations).
  58. */
  59. native file_log();
  60. /*
  61. Function: file_exists(file[]);
  62. Description: Checks if a specified file exists.
  63. Params:
  64. file[] - The name of the file to be checked for existence.
  65. Returns: True if success, false if not.
  66. */
  67. native file_exists(file[]);
  68. /*
  69. Function: f_open(file[], mode[] = "r");
  70. Description: Opens a file for a reading operation.
  71. Params:
  72. file[] - The name of the file to be opened.
  73. mode[] (Optional) - This can be used to set the mode, use "w" for write, "r" for read and "a" for append.
  74. Returns: The file handle if success, else it returns false.
  75. */
  76. native File:f_open(file[], mode[] = "r");
  77. /*
  78. Function: f_close(File: file);
  79. Description: Closes a file opened with f_open.
  80. Params:
  81. File:file - The handler of the file to be closed
  82. Returns: True if success, false if not.
  83. */
  84. native f_close(File: file);
  85. /*
  86. Function: f_read(File: file, storage[], size = sizeof(storage));
  87. Description: Reads from file that was opened by f_open line by line.
  88. Params:
  89. File:file - The handler of the file to be read from.
  90. storage[] - The string to store the read data from.
  91. size - This parameter does not need to be set by you.
  92. Returns: True if success, false if not.
  93. */
  94. native f_read(File: file, storage[], size = sizeof(storage));
  95. /*
  96. Function: f_write(File: file, string[]);
  97. Description: Writes to a file that has been opened using f_open.
  98. Params:
  99. File:file - The handler of the file to be read from.
  100. string[] - The string to write to the file.
  101. Returns: True if success, false if not.
  102. */
  103. native f_write(File: file, string[]);
  104. /*
  105. Function: dir_create(directory[]);
  106. Description: Creates a directory.
  107. Params:
  108. directory[] - The path of the directory to be created.
  109. Returns: True if success, false if not.
  110. */
  111. native dir_create(directory[]);
  112. /*
  113. Function: dir_delete(directory[]);
  114. Description: Deletes a directory.
  115. Params:
  116. directory[] - The path of the directory to be deleted.
  117. Returns: True if success, false if not.
  118. */
  119. native dir_delete(directory[]);
  120. /*
  121. Function: dir_exists(directory[]);
  122. Description: Checks if a directory exists
  123. Params:
  124. directory[] - The path of the directory to be deleted.
  125. Returns: 1 if it exists, 2 if it is a file and 0 if it does not exist.
  126. */
  127. native dir_exists(directory[]);
  128. /*
  129. Function: dir:dir_open(directory[]);
  130. Description: Opens a directory
  131. Params:
  132. directory[] - The path of the directory to be opened.
  133. Returns: 1 if it exists, and 0 if it does not exist.
  134. */
  135. native dir:dir_open(directory[]);
  136. /*
  137. Function: dir_close(dir:handle);
  138. Description: Closes a directory
  139. Params:
  140. dir:handle - The handle of the directory to close that was previously opened.
  141. Returns: Nothing.
  142. */
  143. native dir_close(dir:handle);
  144. /*
  145. Function: dir_list(dir:handle, storage[], &type, length = sizeof(storage));
  146. Description: Reads through a directory, listing each file/sub-directory one by one.
  147. Params:
  148. dir:handle - The handle of the directory that is open to read from.
  149. storage[] - Where the name of the file/directory is stored.
  150. type - Where the type of directory is stored, can be either 1 or 2
  151. (optional) length - This is not needed unless you are passing an array without any length, in which case, use strlen with your array.
  152. Returns: 1 if there a sub-directory/file was found, 0 if there wasn't.
  153. */
  154. native dir_list(dir:handle, storage[], &type, length = sizeof(storage));
  155. // FM_DIR defines a directory and FM_FILE defines a file
  156. // when using dir_list, these will be the types returned.
  157. #define FM_DIR 1
  158. #define FM_FILE 2