Advanced PowerBuilder

HomePrevious Lesson: Frequently Used MS-Windows APIs
Next Lesson: Finding the Current Directory

Copying the Specified File

Declare a local external function as shown below.
FUNCTION boolean ufx_CopyFile(ref string cfrom, &
    ref string cto, boolean flag) LIBRARY "Kernel32.dll" &
    ALIAS FOR "CopyFileA"

The following code calls ufx_CopyFile() which is an alias for CopyFileA() function. This function doesn't display any dialog box, it simply copies the file. The third argument tells to the function that whether it should overwrite the target file if already exists or not.
// Object: cb_copy_file
// Event: Clicked
if isNull(trim(sle_SourceFile.Text)) OR &
   isNull(trim(sle_TargetFile.Text)) THEN
	  Return
end if
boolean lb_rc
String ls_Source, ls_target
ls_Source = trim( sle_SourceFile.Text )
ls_target = trim( sle_TargetFile.Text )
lb_rc = ufx_CopyFile( ls_Source, ls_Target, &
			                  cbx_overwrite.checked )
MessageBox("CopyFile", string(lb_rc))
HomePrevious Lesson: Frequently Used MS-Windows APIs
Next Lesson: Finding the Current Directory