FileDelete: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Portuguese version indexed)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server client function}}
Deletes the specified file.
Deletes the specified file.


==Syntax==
==Syntax==
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool fileDelete ( string filePath )
bool fileDelete ( string filePath )
</syntaxhighlight>
</syntaxhighlight>
{{OOP|This function is a static function underneath the File class.|[[File]].delete}}


===Required Arguments===
===Required Arguments===
Line 13: Line 13:
:For example, if you want to delete a file name "myFile.txt" in the resource 'fileres', it can be deleted from another resource this way: ''fileDelete(":fileres/myFile.txt")''.
:For example, if you want to delete a file name "myFile.txt" in the resource 'fileres', it can be deleted from another resource this way: ''fileDelete(":fileres/myFile.txt")''.
:If the file is in the current resource, only the file path is necessary, e.g. ''fileDelete("myFile.txt")''.
:If the file is in the current resource, only the file path is necessary, e.g. ''fileDelete("myFile.txt")''.
</section>
{{New feature|3.0110|1.1|
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool fileDelete ( string filePath [, string accessType = "public" ] )
</syntaxhighlight>
===Required Arguments===
*'''filePath:''' The [[filepath]] of the file to delete in the following format: '''":resourceName/path"'''. 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
:For example, if you want to delete a file name "myFile.txt" in the resource 'fileres', it can be deleted from another resource this way: ''fileDelete(":fileres/myFile.txt")''.
:If the file is in the current resource, only the file path is necessary, e.g. ''fileDelete("myFile.txt")''.
===Optional Arguments===
*'''accessType :''' This setting determines whether to delete the public or private version of the file at '''filePath'''
** "public" will delete the file that is shared by all servers.
** "private" will delete the file that only the current server is allowed to access. Note: It is only possible to delete a private file if it was previously saved as ''"private"'' by the current server.
</section>
}}


===Returns===
===Returns===
Line 45: Line 24:
     fileWrite(newFile, "This is a test file!")        -- write a text line
     fileWrite(newFile, "This is a test file!")        -- write a text line
     fileClose(newFile)                                -- close the file once you're done with it
     fileClose(newFile)                                -- close the file once you're done with it
     fileDelete(newFile)                               -- delete file
     fileDelete("test.txt")                           -- delete file
end
end
</syntaxhighlight>
</syntaxhighlight>
Line 51: Line 30:
==See Also==
==See Also==
{{File_functions}}
{{File_functions}}
[[pt-br:fileDelete]]

Latest revision as of 17:45, 20 December 2023

Deletes the specified file.

Syntax

bool fileDelete ( string filePath )

OOP Syntax Help! I don't understand this!

Note: This function is a static function underneath the File class.
Method: File.delete(...)


Required Arguments

  • filePath: The filepath of the file to delete in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
For example, if you want to delete a file name "myFile.txt" in the resource 'fileres', it can be deleted from another resource this way: fileDelete(":fileres/myFile.txt").
If the file is in the current resource, only the file path is necessary, e.g. fileDelete("myFile.txt").

Returns

Returns true if successful, false otherwise (for example if there exists no file with the given name, or it does exist but is in use).

Example

This example will show us how to create a file "text.txt" spell it "This is a test file!", Close the file and delete it:

local newFile = fileCreate("test.txt")                -- attempt to create a new file
if (newFile) then                                     -- check if the creation succeeded
    fileWrite(newFile, "This is a test file!")        -- write a text line
    fileClose(newFile)                                -- close the file once you're done with it
    fileDelete("test.txt")                            -- delete file
end

See Also