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("AutoPlay\\Docs\\*.txt", _TempFolder .. "\\Text Files", false);

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

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 autoplay.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 on the CD-ROM to the destination.
StatusDlg.Show(MB_ICONNONE, false);
File.Copy("AutoPlay\\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 on the CD-ROM 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