File.GetSize

number File.GetSize ( 

string Filename )

Example 1

file_size = File.GetSize(_TempFolder .. "\\setup.exe");

Gets the size (in bytes) of the file "setup.exe" located in the user's Temp directory and stores it in the variable "file_size."

Note: _TempFolder is a built-in variable that contains the path to the user's system "Temp" folder.

Example 2

-- Searches for a specific file on the user's system.
location = File.Find("C:\\", "target.txt", false, false, nil);

if (location ~= nil) then
    -- Check the size of the first file that was found.
    file_size = File.GetSize(location[1]);

    if (file_size ~= -1) then
       -- See if the file is 25 bytes. Display a valid or invalid file message to the user.
       if (file_size == 25) then
           Dialog.Message("Success", "The file on your system has been validated.");
       else
           Dialog.Message("Failure", "The file on your system is not valid.");
       end
   else
       Dialog.Message("Failure", "The file on your system could not be validated.");
   end
else
   -- Display a message that the target file was not found.
   Dialog.Message("Notice","The file 'target.txt' was not found.");
end

Searches for a file called "target.txt" in the root of the C:\ drive. If the file is found, its file size is read and compared to the value 25 bytes. Based on the validation results, an appropriate dialog message is displayed.

Example 3

g_FolderSize = 0;

-- This function determines the size of a file and adds it to the total.
-- This function is used as the callback function for the File.Find action in this example.
function OnFileFound(Path)
    local nSize = File.GetSize(Path);
    g_FolderSize = g_FolderSize + nSize;
    return true;
end

-- Allow the user to browse for a folder whose size they want.
local strFolder = Dialog.FolderBrowse("Find a folder",Shell.GetFolder(SHF_MYDOCUMENTS));

StatusDlg.Show();
tblFiles = File.Find(strFolder,"*.*",true,false,nil,OnFileFound);
StatusDlg.Hide();
Dialog.Message("Size",String.GetFormattedSize(g_FolderSize));

This example calculates the total size of a selected folder's contents. To accomplish this, the File.Find action is called with the callback function called "OnFileFound".

See also:  Related Actions