FileGetSize: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Portuguese version indexed)
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server client function}}


Returns the total size in bytes of the given file.
Returns the total size in bytes of the given file.
Line 8: Line 8:
int fileGetSize ( file theFile )
int fileGetSize ( file theFile )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[file]]:getSize|size}}


===Required Arguments===
===Required Arguments===
Line 16: Line 17:


==Example==
==Example==
<section name="Server" class="server" show="true">
In this example we will upload any (in the example config.xml) xml file and create a copy in a new folder with the name of copy-config.xml
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function()
local newFile = fileCreate("test.txt")                -- attempt to create a new file
local newFile = fileCreate("test.txt")                -- attempt to create a new file
if (newFile) then                                      -- check if the creation succeeded
if (newFile) then                                      -- check if the creation succeeded
fileWrite(newFile, "This is a test file!")        -- write a text line
fileWrite(newFile, "This is a test file!")        -- write a text line
local size = fileGetSize(newFile)              -- get size
local size = fileGetSize ( newFile )              -- get size
if size then
if size then
outputChatBox("Size of test.txt is: "..size, source) -- output size
outputChatBox("Size of test.txt is: " .. size, source) -- output size
        end
else
fileClose(newFile)                                -- close the file once you're done with it
outputChatBox("Sorry, test.txt dont have size ;)", source)
                end
fileClose(newFile)                                -- close the file once you're done with it
end
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{File functions}}
{{File functions}}
[[Category:Needs Example]]
[[pt-br:fileGetSize]]

Latest revision as of 18:55, 20 December 2023

Returns the total size in bytes of the given file.

Syntax

int fileGetSize ( file theFile )

OOP Syntax Help! I don't understand this!

Method: file:getSize(...)
Variable: .size


Required Arguments

  • theFile: the file handle you wish to get the size of.

Returns

Returns the file size if successful, or false if an error occured (e.g. an invalid file handle was passed).

Example

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
	local size = fileGetSize(newFile)              -- get size
	if size then
		outputChatBox("Size of test.txt is: "..size, source) -- output size
        end
	fileClose(newFile)                                -- close the file once you're done with it
end

See Also