5 #if defined _files_included
8 #define _files_included
10 /* @note All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
14 FileType_Unknown = 0, /* Unknown file type (device/socket) */
15 FileType_Directory = 1, /* File is a directory */
16 FileType_File = 2, /* File is a file */
19 #define PLATFORM_MAX_PATH 256
26 * @brief Opens a directory/folder for contents enumeration.
27 * @note Directories are closed with CloseHandle().
28 * @note Directories Handles can be cloned.
30 * @param path Path to open.
31 * @return A Handle to the directory, INVALID_HANDLE on open error.
33 native Handle:OpenDirectory(const String:path[]);
36 * @brief Reads the current directory entry as a local filename, then moves to the next file.
37 * @note Contents of buffers are undefined when returning false.
38 * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
40 * @param dir Handle to a directory.
41 * @param buffer String buffer to hold directory name.
42 * @param maxlength Maximum size of string buffer.
43 * @param type Optional variable to store the file type.
44 * @return True on success, false if there are no more files to read.
45 * @error Invalid or corrupt Handle.
47 native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
50 * @brief Opens a file.
51 * @note Files are closed with CloseHandle().
52 * @note File Handles can be cloned.
54 * @param file File to open.
55 * @param mode Open mode.
56 * @return A Handle to the file, INVALID_HANDLE on open error.
58 native Handle:OpenFile(const String:file[], const String:mode[]);
61 * @brief Deletes a file.
63 * @param path Path of the file to delete.
64 * @return True on success, false otherwise.
66 native bool:DeleteFile(const String:path[]);
69 * @brief Reads a line from a text file.
71 * @param hndl Handle to the file.
72 * @param buffer String buffer to hold the line.
73 * @param maxlength Maximum size of string buffer.
74 * @return True on success, false otherwise.
76 native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
79 * @brief Tests if the end of file has been reached.
81 * @param file Handle to the file.
82 * @return True if end of file has been reached, false otherwise.
84 native bool:IsEndOfFile(Handle:file);
87 * @brief Sets the file position indicator.
89 * @param file Handle to the file.
90 * @param position Position relative to what is specified in whence.
91 * @param whence Look at the SEEK_* definitions.
92 * @return True on success, false otherwise.
94 native bool:FileSeek(Handle:file, position, whence);
97 * @brief Get current position in the file.
99 * @param file Handle to the file.
100 * @return Value for the file position indicator.
102 native FilePosition(Handle:file);
105 * @brief Checks if a file exists.
107 * @param path Path to the file.
108 * @return True if the file exists, false otherwise.
110 native bool:FileExists(const String:path[]);
113 * @brief Renames a file.
115 * @param newpath New path to the file.
116 * @param oldpath Path to the existing file.
117 * @return True on success, false otherwise.
119 native bool:RenameFile(const String:newpath[], const String:oldpath[]);
122 * @brief Checks if a directory exists.
124 * @param path Path to the directory.
125 * @return True if the directory exists, false otherwise.
127 native bool:DirExists(const String:path[]);
130 * @brief Get the file size in bytes.
132 * @param path Path to the file.
133 * @return File size in bytes, -1 if file not found.
135 native FileSize(const String:path[]);
138 * @brief Removes a directory.
139 * @note On most Operating Systems you cannot remove a directory which has files inside it.
141 * @param path Path to the directory.
142 * @return True on success, false otherwise.
144 native bool:RemoveDir(const String:path[]);
147 * @brief Writes a line of text in a file.
148 * @note This native will append the newline character.
150 * @param hndl Handle to the file.
151 * @param format Formatting rules.
152 * @param ... Variable number of format parameters.
153 * @return True on success, false otherwise.
155 native bool:WriteFileLine(Handle:hndl, const String:format[], {Handle,Float,String,_}:...);