Copy A file from one Directory to another Directory in Powerbuilder
Published on 05 October 16
1
1
Copy A file from one directory to another directory in Powerbuilder
window -w_filecopy
objects :
single line edit - sle_1,sle_2
buttons - cb_1,cb_2 for choosing the source file and destination path+filename ,cb_3 for the copying file
// Object :: cb_1
integer li_rtn
string docpath,docname
li_rtn = GetFileOpenName("Select File", &
docpath, docname, "DOC", &
+ "All Files (*.*), *.*,Text Files (*.TXT),*.TXT,Doc Files (*.DOC),*.DOC", &
"C:\Program Files\Sybase", 18)
sle_1.text=docpath
//Object :: cb_2
integer li_rc
string docpath,docfile
li_rc= GetFileSaveName ( "Select File", &
docpath, docfile, "DOC", &
+ "All Files (*.*), *.*,Text Files (*.TXT),*.TXT,Doc Files (*.DOC),*.DOC", &
"C:\Program Files\Sybase", &
32770)
sle_2.text=docpath
//Object :: cb_3
integer li_ret
if righttrim(lefttrim(sle_1.text))='' or lefttrim(righttrim(sle_2.text))='' then
MessageBox("Warning!!","Please choose the source and destination files Names")
close(parent)
else
li_ret=parent.f_Filecopy(sle_1.text,sle_2.text)
if li_ret=1 then
MessageBox("Success","FileCopied Successfully")
Else
MessageBox("Failed","Unable to copy the file")
end if
end if
// create a function with two arguments 1 for source path(with file name and extention in it )
// another for destination path (with file name and extention in it )
f_filecopy(string ssource,string sdest) // returns integer
Int iSourceHandle, iDestHandle, iLoops, i,li_rtn
Long lFileLen, lBytesRead, lNewPos
blob b, bTot
string docpath,docname
SetPointer(HourGlass!)
// Check file length
lFileLen = FileLength (sSource)
// Determine the number of characters within the file
If lFileLen > 32766 Then
If Mod(lFileLen, 32766) = 0 Then
iLoops = lFileLen/32766
Else
iLoops = (lFileLen/32766) + 1
End If
Else
//continues
iLoops = 1
End If
iSourceHandle = FileOpen (sSource,streammode!,read!,Shared!)
iDestHandle = FileOpen (sDest,streammode!,Write!,Shared!, Replace!)
FOR i = 1 To iLoops
lBytesRead = FileRead(iSourceHandle, b)
FileWrite(iDestHandle, b)
FileSeek(iDestHandle,32766 * i, FromBeginning!)
lNewPos = lNewPos + lBytesRead
FileSeek(iSourceHandle,lNewPos, FromBeginning!)
Next
FileClose( iSourceHandle)
FileClose(iDestHandle)
Return 1
This blog is listed under
Development & Implementations
Community
Related Posts:
You may also be interested in
Share your perspective
Share your achievement or new finding or bring a new tech idea to life. Your IT community is waiting!
Thank you for sharing. The code is really helpful.