File.Copy

File.Copy ( 

string   Source,

string   Destination,

boolean  Recurse = true,

boolean  Overwrite = true,

boolean  AbortOnFail = false,

boolean  IncludeHiddenFiles = true,

function CallbackFunction = nil )

Example 1

File.Copy(_SourceFolder.."\\*.txt", _TempFolder .. "\\Text Files", false);

Copies all of the text files from the source folder (_SourceFolder) into a subfolder called "Text Files" inside the user's temp folder, and does not go into any subfolders inside the source folder as it searches for files ending in .txt.

Note: _SourceFolder is a built-in variable that contains the path to the folder where the setup.exe file is located.

Example 2

File.Copy(_SourceFolder .. "\\hidden.dat", _TempFolder .. "\\z3j2rlk\\sneaky.exe", false, true, false, true, CB_Copy);

Copies a file named "hidden.dat" from the folder where the setup.exe is located to a folder named "z3j2rlk" in the user's temp folder, renaming the file to "sneaky.exe" in the process. The recurse option is turned off, and the other boolean parameters are set to their default values. A function named CB_Copy will be called whenever progress is made in the copy operation (i.e. every time x number of bytes are copied).

Example 3

-- Get the path to the user's My Documents folder.
DestFolder = Shell.GetFolder(SHF_MYDOCUMENTS);

-- Create a folder in the user's My Documents folder called "Copied Files".
Folder.Create(DestFolder.."\\Copied Files");

--Copy all files within the Docs folder in the source folder to the destination.
StatusDlg.Show(MB_ICONNONE, false);
File.Copy(_SourceFolder.."\\Docs\\*.*", DestFolder.."\\Copied Files\\", true, true, false, true, nil);

-- Check to see if the File.Copy action failed by getting it's error code.
error = Application.GetLastError();
StatusDlg.Hide();

-- If it failed (not equal to 0), display a dialog informing the user.
-- If it succeeded, open an explore window showing the "Copied Files" folder.
if error ~= 0 then
    result = Dialog.Message("Error", "There was an error copying the files to your system. Please try again.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
else
    Shell.Execute(DestFolder.."\\Copied Files", "explore", "", "", SW_SHOWNORMAL);
end

Copies all files from the "Docs" folder in the source folder to a folder called "Copied Files" in the user's My Documents folder. If the operation fails, an error message is displayed. If the operation succeeds, the folder is opened in an explore window.

See also:  Related Actions