3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _files_included
19 #define _files_included
21 /* @global All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
28 FileType_Unknown = 0, /* Unknown file type (device/socket) */
29 FileType_Directory = 1, /* File is a directory */
30 FileType_File = 2, /* File is a file */
33 #define PLATFORM_MAX_PATH 256 /**< Maximum path length. */
35 #define SEEK_SET 0 /**< Seek from start. */
36 #define SEEK_CUR 1 /**< Seek from current position. */
37 #define SEEK_END 2 /**< Seek from end position. */
44 Path_SM, /**< SourceMod root folder */
48 * Builds a path relative to the SourceMod folder.
50 * @param type Type of path to build as the base.
51 * @param buffer Buffer to store the path.
52 * @param maxlength Maximum length of buffer.
53 * @param fmt Format string.
54 * @param ... Format arguments.
55 * @return Number of bytes written to buffer (not including null terminator).
57 native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], any:...);
60 * Opens a directory/folder for contents enumeration.
61 * @note Directories are closed with CloseHandle().
62 * @note Directories Handles can be cloned.
64 * @param path Path to open.
65 * @return A Handle to the directory, INVALID_HANDLE on open error.
67 native Handle:OpenDirectory(const String:path[]);
70 * Reads the current directory entry as a local filename, then moves to the next file.
71 * @note Contents of buffers are undefined when returning false.
72 * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
74 * @param dir Handle to a directory.
75 * @param buffer String buffer to hold directory name.
76 * @param maxlength Maximum size of string buffer.
77 * @param type Optional variable to store the file type.
78 * @return True on success, false if there are no more files to read.
79 * @error Invalid or corrupt Handle.
81 native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
85 * @note Files are closed with CloseHandle().
86 * @note File Handles can be cloned.
88 * @param file File to open.
89 * @param mode Open mode.
90 * @return A Handle to the file, INVALID_HANDLE on open error.
92 native Handle:OpenFile(const String:file[], const String:mode[]);
97 * @param path Path of the file to delete.
98 * @return True on success, false otherwise.
100 native bool:DeleteFile(const String:path[]);
103 * Reads a line from a text file.
105 * @param hndl Handle to the file.
106 * @param buffer String buffer to hold the line.
107 * @param maxlength Maximum size of string buffer.
108 * @return True on success, false otherwise.
110 native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
113 * Tests if the end of file has been reached.
115 * @param file Handle to the file.
116 * @return True if end of file has been reached, false otherwise.
118 native bool:IsEndOfFile(Handle:file);
121 * Sets the file position indicator.
123 * @param file Handle to the file.
124 * @param position Position relative to what is specified in whence.
125 * @param whence Look at the SEEK_* definitions.
126 * @return True on success, false otherwise.
128 native bool:FileSeek(Handle:file, position, whence);
131 * Get current position in the file.
133 * @param file Handle to the file.
134 * @return Value for the file position indicator.
136 native FilePosition(Handle:file);
139 * Checks if a file exists.
141 * @param path Path to the file.
142 * @return True if the file exists, false otherwise.
144 native bool:FileExists(const String:path[]);
149 * @param newpath New path to the file.
150 * @param oldpath Path to the existing file.
151 * @return True on success, false otherwise.
153 native bool:RenameFile(const String:newpath[], const String:oldpath[]);
156 * Checks if a directory exists.
158 * @param path Path to the directory.
159 * @return True if the directory exists, false otherwise.
161 native bool:DirExists(const String:path[]);
164 * Get the file size in bytes.
166 * @param path Path to the file.
167 * @return File size in bytes, -1 if file not found.
169 native FileSize(const String:path[]);
172 * Flushes a file's buffered output; any buffered output
173 * is immediately written to the file.
175 * @param file Handle to the file.
176 * @return True on success, false on failure.
178 native FlushFile(Handle:file);
181 * Removes a directory.
182 * @note On most Operating Systems you cannot remove a directory which has files inside it.
184 * @param path Path to the directory.
185 * @return True on success, false otherwise.
187 native bool:RemoveDir(const String:path[]);
190 * Writes a line of text in a file.
191 * @note This native will append the newline character.
193 * @param hndl Handle to the file.
194 * @param format Formatting rules.
195 * @param ... Variable number of format parameters.
196 * @return True on success, false otherwise.
198 native bool:WriteFileLine(Handle:hndl, const String:format[], any:...);