Page 1 of 1

Copy File/Directory with explorer [Resolved]

Posted: Wed Nov 09, 2016 6:23 pm
by Kwai chang caine
Hello at all

Is it possible, to ask to the explorer with PB, to copy/cut a full directory or one or several files like if it's him he do the job (when i use the mouse for exampler)
Image

Have a good day

Re: Copy File/Directory with explorer

Posted: Wed Nov 09, 2016 9:50 pm
by Lunasole
Hi ^^ Yes, and it is even more easy than I've expected:

Code: Select all

EnableExplicit

; paths
Global Dim SrcFiles$(1), Dim OutFiles$(1)
	SrcFiles$(0) = "C:\1.txt"
	OutFiles$(0) = "D:\1.txt"


; fill structure
; see similar constants for other ops: like #FO_MOVE, #FOF_SILENT
Define A.SHFILEOPSTRUCT
	With A
		\hwnd = 0
		\wFunc = #FO_COPY			; what to do
		\pFrom = @SrcFiles$(0)		; list of source paths
		\pTo = @OutFiles$(0)		; list of destination paths
		\fFlags = #FOF_ALLOWUNDO	; how to do
	EndWith

; finally copy file1 to file2 using explorer shell
SHFileOperation_(A)
I thought It would be needed to use interfaces for this, but then remembered than nice API.
Look here for the full info about it: https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Re: Copy File/Directory with explorer

Posted: Wed Nov 09, 2016 10:45 pm
by Kwai chang caine
Thanks a lot LUNASOLE.
I can't test it for the moment, i'm on smartphone, but tommorow i run it, in the first hour, and give to you news :wink:

Have a very good night 8)

Re: Copy File/Directory with explorer

Posted: Thu Nov 10, 2016 3:40 am
by OldSkoolGamer
Here's one I got from the forum awhile ago, cannot remember who wrote it, but it works great:

Code: Select all

Procedure.l FileOp(FromLoc.s, ToLoc.s, Flag)
  ;Flag can be the following: #FO_COPY, #FO_DELETE, #FO_MOVE, #FO_RENAME
  Switches.SHFILEOPSTRUCT ;Windows API Structure
  ;The filename needs to be double null-terminated.
  temp1$=Space(#MAX_PATH+SizeOf(character))
  RtlZeroMemory_(@temp1$, #MAX_PATH+SizeOf(character))
  PokeS(@temp1$, FromLoc)
  temp2$=Space(#MAX_PATH+SizeOf(character))
  RtlZeroMemory_(@temp2$, #MAX_PATH+SizeOf(character))
  PokeS(@temp2$, ToLoc)
  Switches\wFunc = Flag
  Switches\pFrom = @temp1$
  Switches\pTo = @temp2$
  Switches\fFlags = #FOF_NOCONFIRMATION | #FOF_NOCONFIRMMKDIR
  Result.l = SHFileOperation_(@Switches)
  ; If cancel was pressed then result will NOT be zero (0)
ProcedureReturn Result
EndProcedure

Re: Copy File/Directory with explorer

Posted: Thu Nov 10, 2016 9:20 am
by RSBasic

Re: Copy File/Directory with explorer

Posted: Thu Nov 10, 2016 10:03 am
by ts-soft

Re: Copy File/Directory with explorer

Posted: Thu Nov 10, 2016 11:07 am
by Kwai chang caine
Hello at ALL !! :D

It's exactely what i want !! 8)

I have tested all your codes and i can copy, even a full folder, like if it's me i command to windows to do the job :shock:

Mixed to the JbBremmer personal explorer
http://forums.purebasic.com/german/view ... aa#p285438
and the FREAK popup windows into a personal gadget
http://www.purebasic.fr/english/viewtop ... 28#p284528
I can now create my personal explorer

At the begining, i search to callback GadgetExplorer or TreeExplorer for modify item name dynamically
But apparently, it's not so simple :|
Now i can, replace the true name of file/folder, by another, and have the hand on all my own window explorer write :mrgreen:

Thanks a lot all my friends
And have the very best better day of the world !!!

Re: Copy File/Directory with explorer [Resolved]

Posted: Thu Nov 10, 2016 8:06 pm
by TerryHough
Unless you actually require the graphic display of the explorer doing the job...

Why not use the native PB command to copy/delete directories. Much faster in my testing without the GUI.
COPY

Code: Select all

Result = CopyDirectory(SourceDirectory$, DestinationDirectory$, "", #PB_FileSystem_Recursive|#PB_FileSystem_Force)
or
DELETE

Code: Select all

Result = DeleteDirectory(Directory$, "", #PB_FileSystem_Recursive|#PB_FileSystem_Force)
Similar commands available at the file level. See "File System" in the manual.

Re: Copy File/Directory with explorer [Resolved]

Posted: Fri Nov 11, 2016 3:07 pm
by Kwai chang caine
Thanks TerryHough. I know the native command :wink:
But i don't know the pb command is more faster 8)

In fact i try to recreate a simple explorer, because i need this explorer translate the real name of file/folder by another i choose.

But for all the other functions (copy, move, delete, etc...) i want do like usualy, and want to let the real explorer do the job for he not become idle :lol:
In fact, my real reason it's me the idle, and not want coding functions already exist in window :mrgreen:

So thanks for your advice 8)