2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
7 * or modified under the Terms and Conditions of its License Agreement, which is found
8 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
9 * may change at any time. To view the latest information, see:
10 * http://www.sourcemod.net/license.php
15 #if defined _files_included
18 #define _files_included
20 /* @note All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
24 FileType_Unknown = 0, /* Unknown file type (device/socket) */
25 FileType_Directory = 1, /* File is a directory */
26 FileType_File = 2, /* File is a file */
29 #define PLATFORM_MAX_PATH 256
37 Path_SM, /* SourceMod root folder */
41 * @brief Builds a path relative to the SourceMod folder.
43 * @param type Type of path to build as the base.
44 * @param buffer Buffer to store the path.
45 * @param maxlength Maximum length of buffer.
46 * @param fmt Format string.
47 * @param ... Format arguments.
48 * @return Number of bytes written to buffer (not including null terminator).
50 native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], ...);
53 * @brief Opens a directory/folder for contents enumeration.
54 * @note Directories are closed with CloseHandle().
55 * @note Directories Handles can be cloned.
57 * @param path Path to open.
58 * @return A Handle to the directory, INVALID_HANDLE on open error.
60 native Handle:OpenDirectory(const String:path[]);
63 * @brief Reads the current directory entry as a local filename, then moves to the next file.
64 * @note Contents of buffers are undefined when returning false.
65 * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
67 * @param dir Handle to a directory.
68 * @param buffer String buffer to hold directory name.
69 * @param maxlength Maximum size of string buffer.
70 * @param type Optional variable to store the file type.
71 * @return True on success, false if there are no more files to read.
72 * @error Invalid or corrupt Handle.
74 native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
77 * @brief Opens a file.
78 * @note Files are closed with CloseHandle().
79 * @note File Handles can be cloned.
81 * @param file File to open.
82 * @param mode Open mode.
83 * @return A Handle to the file, INVALID_HANDLE on open error.
85 native Handle:OpenFile(const String:file[], const String:mode[]);
88 * @brief Deletes a file.
90 * @param path Path of the file to delete.
91 * @return True on success, false otherwise.
93 native bool:DeleteFile(const String:path[]);
96 * @brief Reads a line from a text file.
98 * @param hndl Handle to the file.
99 * @param buffer String buffer to hold the line.
100 * @param maxlength Maximum size of string buffer.
101 * @return True on success, false otherwise.
103 native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
106 * @brief Tests if the end of file has been reached.
108 * @param file Handle to the file.
109 * @return True if end of file has been reached, false otherwise.
111 native bool:IsEndOfFile(Handle:file);
114 * @brief Sets the file position indicator.
116 * @param file Handle to the file.
117 * @param position Position relative to what is specified in whence.
118 * @param whence Look at the SEEK_* definitions.
119 * @return True on success, false otherwise.
121 native bool:FileSeek(Handle:file, position, whence);
124 * @brief Get current position in the file.
126 * @param file Handle to the file.
127 * @return Value for the file position indicator.
129 native FilePosition(Handle:file);
132 * @brief Checks if a file exists.
134 * @param path Path to the file.
135 * @return True if the file exists, false otherwise.
137 native bool:FileExists(const String:path[]);
140 * @brief Renames a file.
142 * @param newpath New path to the file.
143 * @param oldpath Path to the existing file.
144 * @return True on success, false otherwise.
146 native bool:RenameFile(const String:newpath[], const String:oldpath[]);
149 * @brief Checks if a directory exists.
151 * @param path Path to the directory.
152 * @return True if the directory exists, false otherwise.
154 native bool:DirExists(const String:path[]);
157 * @brief Get the file size in bytes.
159 * @param path Path to the file.
160 * @return File size in bytes, -1 if file not found.
162 native FileSize(const String:path[]);
165 * @brief Removes a directory.
166 * @note On most Operating Systems you cannot remove a directory which has files inside it.
168 * @param path Path to the directory.
169 * @return True on success, false otherwise.
171 native bool:RemoveDir(const String:path[]);
174 * @brief Writes a line of text in a file.
175 * @note This native will append the newline character.
177 * @param hndl Handle to the file.
178 * @param format Formatting rules.
179 * @param ... Variable number of format parameters.
180 * @return True on success, false otherwise.
182 native bool:WriteFileLine(Handle:hndl, const String:format[], {Handle,Float,String,_}:...);