Re: CopyFileEx API call
Posted: Sun Nov 17, 2019 6:48 pm
Excellent! That worked as expected. Much appreciated
http://www.purebasic.com
https://www.purebasic.fr/english/
What I want to have is something that copy files as fast as ROBOCOPY but to display some sort ofinfratec wrote:Programming is not copy and paste
It compiles now and is starting, but I have not tested it.Code: Select all
EnableExplicit ;====================================================================== ; ShareCopy.PB - A Muli-Function Copy Tool that uses: Shell32.dll ; I found a subroutine on VB web-site - author unknown ; modified for PureBasic - Public Domain ; Bob Houle - updated Nov 02/02 [url]mailto:blueb@shaw.ca[/url] ;====================================================================== #Window1 = 1 #Btn_Copy = 1 #Btn_Move = 2 #Btn_Rename = 3 #Btn_Delete = 4 #Btn_Quit = 5 #W1String1 = 6 #W1String2 = 7 #W1Check1 = 8 #W1Check2 = 9 #W1Check3 = 10 #W1Check4 = 11 #W1Check5 = 12 #W1Text1 = 13 #W1Text2 = 14 #Window1Flags = #PB_Window_MinimizeGadget | #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered Procedure.i Button_Click(Index.i) ;define variables Protected wFunc.u Protected lresult.l Protected fFlags.u Protected.i ChkDir, ChkFilesOnly, ChkRename, ChkSilent,ChkYesToAll Protected FromDirectory$, ToDirectory$ Protected SHFileOp.SHFILEOPSTRUCT ;Windows API Structure ;Get status of checkboxes ChkDir = GetGadgetState(#W1Check4) ChkFilesOnly = GetGadgetState(#W1Check5) ChkRename = GetGadgetState(#W1Check3) ChkSilent = GetGadgetState(#W1Check1) ChkYesToAll = GetGadgetState(#W1Check2) ;Get the edit box values FromDirectory$ = GetGadgetText(#W1String1) ToDirectory$ = GetGadgetText(#W1String2) ;Find out which button was pressed Select Index Case #Btn_Copy wFunc = #FO_COPY Case #Btn_Move wFunc = #FO_MOVE Case #Btn_Rename wFunc = #FO_RENAME Case #Btn_Delete ChkYesToAll = 0 ;No mattter what - confirm Deletes! Prevents OOPS! wFunc = #FO_DELETE EndSelect If ChkSilent fFlags | #FOF_SILENT EndIf If ChkYesToAll fFlags | #FOF_NOCONFIRMATION EndIf If ChkRename fFlags | #FOF_RENAMEONCOLLISION EndIf If ChkDir fFlags | #FOF_NOCONFIRMMKDIR EndIf If ChkFilesOnly fFlags | #FOF_FILESONLY EndIf ; NOTE: If you add the #FOF_ALLOWUNDO Flag you can move ; a file to the Recycle Bin instead of deleting it. SHFileOp\wFunc = wFunc SHFileOp\pFrom = @FromDirectory$ SHFileOp\pTo = @ToDirectory$ SHFileOp\fFlags = fFlags lresult = SHFileOperation_(SHFileOp) ; If User hit Cancel button While operation is in progress, ; the fAnyOperationsAborted parameter will be true ; - see win32api.inc For Structure details. If lresult = 0 Or SHFileOp\fAnyOperationsAborted ProcedureReturn 0 EndIf MessageRequester("Operation Has Completed", "PureBasic Rules!", 0) ProcedureReturn lresult EndProcedure Define.i Event If OpenWindow(#Window1, 0, 0, 500, 230, "Window-Like File Operations", #Window1Flags) ButtonGadget(#Btn_Copy,7,200 ,89,25,"Copy") ButtonGadget(#Btn_Move,105,200 ,89,25,"Move") ButtonGadget(#Btn_Rename,205,200 ,89,25,"Rename") ButtonGadget(#Btn_Delete,305,200 ,89,25,"Delete") ButtonGadget(#Btn_Quit,405,200 ,89,25,"Quit", 1) StringGadget(#W1String1,220,8,250,21,"") StringGadget(#W1String2,220,30 ,250,21,"") CheckBoxGadget(#W1Check1,90,80 ,391,17,"Don't display a progress dialog box") CheckBoxGadget(#W1Check2,90,100 ,403,17,"Respond with 'Yes to all' for any dialog box that is displayed") CheckBoxGadget(#W1Check3,90,120 ,404,17,"Rename the file (eg:'Copy #1 of...') if the target name already exists") CheckBoxGadget(#W1Check4,90,140 ,384,17,"Do not confirm the creation of a new directory if the operation requires it") CheckBoxGadget(#W1Check5,90,160 ,398,17,"Perform the operation only on files if a wildcard filename (*.*) is specified") TextGadget(#W1Text1,50,12 ,161,17,"Source File or Folder", #PB_Text_Right) TextGadget(#W1Text2,50,35,161,17,"Destination File or Folder", #PB_Text_Right) Repeat Event = WaitWindowEvent() Select Event Case #PB_Event_Gadget Select EventGadget() Case #Btn_Copy Button_Click(#Btn_Copy) Case #Btn_Move Button_Click(#Btn_Move) Case #Btn_Rename Button_Click(#Btn_Rename) Case #Btn_Delete Button_Click(#Btn_Delete) Case #Btn_Quit Event = #PB_Event_CloseWindow EndSelect EndSelect Until Event = #PB_Event_CloseWindow EndIf
But I think it is really outdated.
So it would be better if you tell us what you want to do, or to have
Yes, I'd like to do that the problem is I don't find any examples to get me started.infratec wrote:Hmm...
then use robocopy or rsync in background (hidden with RunProgram()) and catch the output.
Thank you, unfortunately this code doesn't work. After I input the source and destination the program just quits without anyinfratec wrote:This forum, like any other, has a search function.
If you search for robocopy, you will find something...
viewtopic.php?f=13&t=50611&hilit=robocopy
Hi BlueB ,blueb wrote:Hi gonpublic2k,
First... WOW! Was that a long time ago, but I have no problem using my Muli-Function Copy Tool on 5.71 (x86) or (x64)
I'm also not sure how robust 'SHFileOperation' is compared to RoboCopy.exe
Having said that... from what I can gather even RoboCopy cannot copy files that are locked open (or in use)
For this I'd suggest: GSCopyPro Version 8.1 https://www.gurusquad.com/GSCOPYPRO
GSCopyPro comes with an 'open file agent' which can copy files that are locked/ opened by other processes.
This point is crucial when copying server files... there is 'always' an open file somewhere in the system. {grin}
Here's their basic help PDF: https://www.gurusquad.com/GSCOPYPro_v81_Admin_Guide.pdf
PS - The 'Enterprise version' has even more options.
• Operates real-time.
• Provides byte-level file replication to save on bandwidth and file copy time.
• Uses compressed data during transmission, making transfers much more efficient and robust.
• Provides WebDAV support.
• Provides the option to replicate data across the internet with data being highly encrypted during
transmission.
Ya kind'a get what you pay for when it comes to backing up servers.
I'd be wary of that statement... look into this closely....you can actually copy files in backup mode which takes care of the issue if a file
is locked.
That's correct Marcus. Thank you all for your support and feedback. I'm not sure if the progressbar method of calculating what files are going to be copied and parsing thatMarc56us wrote:It's great that you want do it yourself to learn rather than using a ready-made product.
So we're not going to do it for you, but give you the method.
A good point is to make a progressbar and to do it, you musk know how many files need to be treated
To make a progress bar, you make a first pass of copy simulation (parameter /L) which allows you to count all the programs that need to be added, modified or deleted.
Then, you run Robocopy in the background and for each displayed line (updated, added, del), you advance the progress bar.
I think Robocopy can copy open files using the Volume Shadows Copy system (I don't remember how it works anymore)
That being said, the principle of a file backup is to make it run off-connection (users) for users and otherwise we inform them that they must close their files at such time and that otherwise they will not be backed up.
For some files such as those in databases this is not a problem because the copy is made using replication system or use Dump file.