Roadcrash
asked on
Follow up on: I want to copy the favorites to another location for restoring it later.....
Following up on https://www.experts-exchange.com/questions/21904991/I-want-to-copy-the-favorites-to-another-location-for-restoring-it-later.html
Hi all
The person for whom i was making this program asked if it was possible for her, to choose the backup location instead of me setting the folder in advance, I managed to get the selected location in an editfield, but how to go from there?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Folders, StdCtrls, ShellApi, FileCtrl, ShlObj, ActiveX;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
btn3: TButton;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
private
// Private declarations
public
// Public declarations
end;
var
Form1: TForm1;
lpbi: TBrowseInfo;
pidlStart: PItemIDList;
Malloc: IMalloc;
whichfolder: string;
pidlSelected: PItemIDList;
implementation
{$R *.DFM}
function Transfer(FromPath, ToPath: String): Boolean;
var lpOpStruct: TSHFileOpStruct;
begin
// Clear struct
FillChar(lpOpStruct, SizeOf(TSHFileOpStruct), 0);
// Set params
lpOpStruct.Wnd:=GetDesktop Window;
lpOpStruct.wFunc:=FO_COPY;
lpOpStruct.pFrom:=PChar(Fr omPath+'\* '#0#0);
lpOpStruct.pTo:=PChar(ToPa th+#0#0);
lpOpStruct.fFlags:=FOF_NOC ONFIRMATIO N or FOF_SILENT or FOF_NOERRORUI or FOF_NOCONFIRMMKDIR;
// Perform the operation
result:=(SHFileOperation(l pOpStruct) = 0) and (lpOpStruct.fAnyOperations Aborted = False);
end;
// Import the favorites
procedure TForm1.btn2Click(Sender: TObject);
var szFavorites: String;
begin
// Get favorites folder
szFavorites:=GetFolderPath (CSIDL_FAV ORITES);
// Check folder
if ((GetFileAttributes(PChar( szFavorite s)) and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) then
begin
// Transfer from backup loaction
Transfer('d:\backup\favori tes', szFavorites);
end;
end;
//this lets the user select a backupfolder with variable name = whichfolder
procedure TForm1.btn3Click(Sender: TObject);
var
lpbi: TBrowseInfo;
pidlStart: PItemIDList;
Malloc: IMalloc;
whichfolder: string;
pidlSelected: PItemIDList;
begin
SHGetSpecialFolderLocation (Handle, $00, pidlStart);
SHGetMalloc(Malloc);
with lpbi do
begin
hwndOwner := Handle;
pidlRoot := pidlStart;
GetMem(pszDisplayName, MAX_PATH);
lpszTitle := PChar('Kies map voor het opslaan....');
ulFlags := $00000051;
lpfn := nil;
end;
pidlSelected := SHBrowseForFolder(lpbi);
if pidlSelected <> nil then
begin
if SHGetPathFromIDList(pidlSe lected, lpbi.pszDisplayName) then
whichfolder := StrPas(lpbi.pszDisplayName );
edt1.Text:=whichfolder; //here i will have the user selected location
Malloc.Free(pidlSelected);
end;
FreeMem(lpbi.pszDisplayNam e);
Malloc.Free(pidlStart);
end;
// Export the favorites
procedure TForm1.btn1Click(Sender: TObject);
var szFavorites: String;
begin
// Get favorites folder
szFavorites:=GetFolderPath (CSIDL_FAV ORITES);
// Check folder
if ((GetFileAttributes(PChar( szFavorite s)) and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) then
begin
// Transfer to backup location
Transfer(szFavorites, 'd:\backup\favorites');
end;
end;
end.
Hi all
The person for whom i was making this program asked if it was possible for her, to choose the backup location instead of me setting the folder in advance, I managed to get the selected location in an editfield, but how to go from there?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Folders, StdCtrls, ShellApi, FileCtrl, ShlObj, ActiveX;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
btn3: TButton;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
private
// Private declarations
public
// Public declarations
end;
var
Form1: TForm1;
lpbi: TBrowseInfo;
pidlStart: PItemIDList;
Malloc: IMalloc;
whichfolder: string;
pidlSelected: PItemIDList;
implementation
{$R *.DFM}
function Transfer(FromPath, ToPath: String): Boolean;
var lpOpStruct: TSHFileOpStruct;
begin
// Clear struct
FillChar(lpOpStruct, SizeOf(TSHFileOpStruct), 0);
// Set params
lpOpStruct.Wnd:=GetDesktop
lpOpStruct.wFunc:=FO_COPY;
lpOpStruct.pFrom:=PChar(Fr
lpOpStruct.pTo:=PChar(ToPa
lpOpStruct.fFlags:=FOF_NOC
// Perform the operation
result:=(SHFileOperation(l
end;
// Import the favorites
procedure TForm1.btn2Click(Sender: TObject);
var szFavorites: String;
begin
// Get favorites folder
szFavorites:=GetFolderPath
// Check folder
if ((GetFileAttributes(PChar(
begin
// Transfer from backup loaction
Transfer('d:\backup\favori
end;
end;
//this lets the user select a backupfolder with variable name = whichfolder
procedure TForm1.btn3Click(Sender: TObject);
var
lpbi: TBrowseInfo;
pidlStart: PItemIDList;
Malloc: IMalloc;
whichfolder: string;
pidlSelected: PItemIDList;
begin
SHGetSpecialFolderLocation
SHGetMalloc(Malloc);
with lpbi do
begin
hwndOwner := Handle;
pidlRoot := pidlStart;
GetMem(pszDisplayName, MAX_PATH);
lpszTitle := PChar('Kies map voor het opslaan....');
ulFlags := $00000051;
lpfn := nil;
end;
pidlSelected := SHBrowseForFolder(lpbi);
if pidlSelected <> nil then
begin
if SHGetPathFromIDList(pidlSe
whichfolder := StrPas(lpbi.pszDisplayName
edt1.Text:=whichfolder; //here i will have the user selected location
Malloc.Free(pidlSelected);
end;
FreeMem(lpbi.pszDisplayNam
Malloc.Free(pidlStart);
end;
// Export the favorites
procedure TForm1.btn1Click(Sender: TObject);
var szFavorites: String;
begin
// Get favorites folder
szFavorites:=GetFolderPath
// Check folder
if ((GetFileAttributes(PChar(
begin
// Transfer to backup location
Transfer(szFavorites, 'd:\backup\favorites');
end;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER