Windows 95/NT Specific routines
unit win95; { For copying, moving and erasing files and folders like Windows 95 Explorer. Date : 06/04/97 This update: 03/08/97 Autor : Rafael Ribas Aguiló (Brazil) e-mail: rribas@unisys.com.br I hope receive bugs corrections by all the people who asked me to send this source code. I also hope to receive other funny functions !!! UPDATES: (18/04/97) Update with many tips and information sent by many people. Thanks to all. (31/08/97) Some refinings two new procedures: Win95AddToRecent and Win95ClearRecentDocs. } interface Uses Classes, ShellApi, ShlObj, Registry, Windows; type Str10 = String[10]; Const fpRootKey ='\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'; fpDesktop : Str10 = 'DESKTOP'; fpFavorites : Str10 = 'FAVORITES'; fpFonts : Str10 = 'FONTS'; fpPersonal : Str10 = 'PERSONAL'; fpPrograms : Str10 = 'PROGRAMS'; fpRecent : Str10 = 'RECENT'; fpSendTo : Str10 = 'SENDTO'; fpStartMenu : Str10 = 'START MENU'; fpStartup : Str10 = 'STARTUP'; fpTemplates : Str10 = 'TEMPLATES'; {Windows Paths} function GetFolderPath(Const FolderName: Str10): String; {Files functions} procedure Win95AddToRecentDocs(Const Filename: string); procedure Win95ClearRecentDocs; {To allow multiple source files, replace spaces with #0} 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 function GetFolderPath(Const FolderName: Str10): String; begin with TRegistry.Create do Try RootKey:=HKEY_CURRENT_USER; OpenKey(fpRootKey,False); Result:=ReadString(FolderName); finally Free; end; end; 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; const Aborted: Boolean = False; var Struct : TSHFileOpStructA; begin 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 RenameOnCollision then fFLags:=fFlags or FOF_RENAMEONCOLLISION; If not Confirm then fFLags:=fFlags or FOF_NOCONFIRMATION; fAnyOperationsAborted:=Aborted; hNameMappings:=nil; lpszProgressTitle:=nil; end; result:=(SHFileOperationA(Struct)=0) and (not Aborted); end; function Win95Move(Owner: Integer; FromFile,ToFile: String; RenameOnCollision, Confirm: boolean): Boolean; const Aborted: Boolean = False; var Struct : TSHFileOpStructA; begin 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 RenameOnCollision then fFLags:=fFlags or FOF_RENAMEONCOLLISION; If Confirm then fFLags:=fFlags or FOF_NOCONFIRMATION; fAnyOperationsAborted:=Aborted; hNameMappings:=nil; lpszProgressTitle:=nil; end; result:=(SHFileOperationA(Struct)=0) and (not Aborted); end; function Win95Erase(Owner: Integer; WichFiles: String; SendToRecycleBin, Confirm: Boolean): Boolean; const Aborted: Boolean = False; var Struct : TSHFileOpStructA; begin 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; fAnyOperationsAborted:=Aborted; hNameMappings:=nil; lpszProgressTitle:=nil; end; result:=(SHFileOperationA(Struct)=0) and (not Aborted); end; end.