Mega Code Archive

 
Categories / Delphi / Files
 

Copying files like window explorer, with flying files... (with attached example)

Title: Copying files like window explorer, with flying files... (with attached example) Question: For those want to make your software show the windows explorer flying files while copying files and also have recent opened files appear at the Documents in the Start Menu. Answer: Here are three functions (not a component) to handle file copying showing those flying files, just like windows explorer. For intuitive use, this functions have logical parameters that simplifies its use. Also are two procedure that help you deal with the Recent Documents in the Windows Start Menu. ======================================================= unit win95; interface Uses Classes, ShellApi, ShlObj, Windows; {Files functions} procedure Win95AddToRecentDocs(Const Filename: string); procedure Win95ClearRecentDocs; function Win95Copy(Owner: Integer; FromFile,ToFile: String; RenameOnCollision, Confirm: boolean): Boolean; function Win95Move(Owner: Integer; FromFile,ToFile: String; RenameOnCollision, Confirm: boolean): Boolean; {If SendToRecycleBin is true then files will be sent to Windows RecycleBin else they will be wiped out} function Win95Erase(Owner: Integer; WichFiles: String; SendToRecycleBin, Confirm: Boolean): Boolean; implementation procedure Win95AddToRecentDocs(Const Filename: string); begin SHAddToRecentDocs(SHARD_PATH, @Filename[1]); end; procedure Win95ClearRecentDocs; begin SHAddToRecentDocs(SHARD_PATH, nil); end; function Win95Copy(Owner: Integer; FromFile,ToFile: String; RenameOnCollision, Confirm: boolean): Boolean; var Struct : TSHFileOpStructA; MultDest: boolean; begin FillChar(Struct, SizeOf(Struct), 0); MultDest:=pos(';',ToFile)0; While pos(';',FromFile)0 do FromFile[pos(';',FromFile)]:=#0; While pos(';',ToFile)0 do ToFile[pos(';',ToFile)]:=#0; FromFile:=FromFile+#0#0; ToFile:=ToFile+#0#0; with Struct do begin wnd :=Owner; wFunc :=FO_Copy; pFrom :=PChar(FromFile); pTo :=PChar(ToFile); fFlags:=FOF_ALLOWUNDO or FOF_FILESONLY; If MultDest then fFLags:=fFlags or FOF_MULTIDESTFILES; If RenameOnCollision then fFLags:=fFlags or FOF_RENAMEONCOLLISION; If not Confirm then begin fFLags:=fFlags or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR; end; hNameMappings:=nil; lpszProgressTitle:=nil; end; result:=(SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted); end; function Win95Move(Owner: Integer; FromFile,ToFile: String; RenameOnCollision, Confirm: boolean): Boolean; var Struct : TSHFileOpStructA; MultDest: boolean; begin FillChar(Struct, SizeOf(Struct), 0); MultDest:=pos(';',ToFile)0; While pos(';',FromFile)0 do FromFile[pos(';',FromFile)]:=#0; While pos(';',ToFile)0 do ToFile[pos(';',ToFile)]:=#0; FromFile:=FromFile+#0#0; ToFile:=ToFile+#0#0; with Struct do begin wnd :=Owner; wFunc :=FO_Move; pFrom :=PChar(FromFile); pTo :=PChar(ToFile); fFlags:=FOF_ALLOWUNDO or FOF_FILESONLY; If MultDest then fFLags:=fFlags or FOF_MULTIDESTFILES; If RenameOnCollision then fFLags:=fFlags or FOF_RENAMEONCOLLISION; If Confirm then fFLags:=fFlags or FOF_NOCONFIRMATION; hNameMappings:=nil; lpszProgressTitle:=nil; end; result:=(SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted); end; function Win95Erase(Owner: Integer; WichFiles: String; SendToRecycleBin, Confirm: Boolean): Boolean; var Struct : TSHFileOpStructA; begin FillChar(Struct, SizeOf(Struct), 0); While pos(';',WichFiles)0 do WichFiles[pos(';',WichFiles)]:=#0; WichFiles:=WichFiles+#0#0; with Struct do begin wnd :=Owner; wFunc :=FO_Delete; pFrom :=PChar(WichFiles); pTo :=nil; If not Confirm then fFlags:=FOF_NOCONFIRMATION; If SendToRecycleBin then fFLags:=fFlags or FOF_ALLOWUNDO or FOF_FILESONLY else fFlags:=fFlags or 0 or FOF_FILESONLY; hNameMappings:=nil; lpszProgressTitle:=nil; end; result:=(SHFileOperationA(Struct)=0) and (not Struct.fAnyOperationsAborted); end; end.