Copy File/Directory with explorer [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Copy File/Directory with explorer [Resolved]

Post 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
Last edited by Kwai chang caine on Thu Nov 10, 2016 11:08 am, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Copy File/Directory with explorer

Post 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
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Copy File/Directory with explorer

Post 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)
ImageThe happiness is a road...
Not a destination
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Copy File/Directory with explorer

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Copy File/Directory with explorer

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Copy File/Directory with explorer

Post 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 !!!
ImageThe happiness is a road...
Not a destination
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Re: Copy File/Directory with explorer [Resolved]

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Copy File/Directory with explorer [Resolved]

Post 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)
ImageThe happiness is a road...
Not a destination
Post Reply