MSI Factory 2.3

File.Copy

File.Copy

This is the first topic This is the last topic  

File.Copy

This is the first topic This is the last topic  

OverviewExamples

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

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

Example 2

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

Copies a file named "hidden.dat" from the drive where the script is run from 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 drive to the destination.

StatusDlg.Show(MB_ICONNONE, false);

File.Copy(_SourceDrive.."\\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 drive 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


Learn More: Indigo Rose Software - MSI Factory - Buy Now - Contact Us