FileGetSize: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Needs example)
Line 16: Line 16:


==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">
--TODO
function()
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
else
outputChatBox("Sorry, test.txt dont have size ;)", source)
fileClose(newFile)                                -- close the file once you're done with it
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{File functions}}
{{File functions}}
[[Category:Needs Example]]
[[Category:Needs Example]]

Revision as of 09:56, 24 May 2010

Returns the total size in bytes of the given file.

Syntax

int fileGetSize ( file theFile )

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

Click to collapse [-]
Server

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

function()
	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
		else
			outputChatBox("Sorry, test.txt dont have size ;)", source)
		fileClose(newFile)                                -- close the file once you're done with it
	end
end

See Also