MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

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
Copy A file from one Directory to another Directory in Powerbuilder - Image 1
Copy A file from one Directory to another Directory in Powerbuilder - Image 2
This blog is listed under Development & Implementations Community

Related Posts:
View Comment (1)
Post a Comment

Please notify me the replies via email.

Important:
  • We hope the conversations that take place on MyTechLogy.com will be constructive and thought-provoking.
  • To ensure the quality of the discussion, our moderators may review/edit the comments for clarity and relevance.
  • Comments that are promotional, mean-spirited, or off-topic may be deleted per the moderators' judgment.
  1. 06 October 16
    1

    Thank you for sharing. The code is really helpful.

You may also be interested in
 
Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top