Groups | Search | Server Info | Login | Register
Groups > comp.lang.pascal.delphi.misc > #709
| From | Richard <nospam@localhost.nil> |
|---|---|
| Newsgroups | comp.lang.pascal.delphi.misc |
| Subject | Re: Open dialog to display directory only (D4) |
| Date | 2015-07-22 19:19 +0200 |
| Message-ID | <d1a1knFomasU1@mid.individual.net> (permalink) |
| References | <mojobd$umt$1@dont-email.me> |
On 20/07/15 23:15, P E Schoen wrote:
> Hopefully there are still people reading this newsgroup...
>
> I am working on a new Delphi project called DupZapper which intends to
> open a directory which contains many duplicate files (in this case,
> email), and then find the duplicates and move them to a separate ZAP
> directory. I can hard code the email directory and then use the Open
> Dialog to select all the files in the folder I want to ZAP, and perhaps
> that is easiest and best. But I would like to know how to navigate to
> the directory in case I want to use this application on a different
> computer or for a different user. My email directory is:
>
> C:\Users\paul_000\AppData\Local\Microsoft\Windows Live Mail\Peschoen (paul)
>
> It would be easy enough to store this file location in a text file for
> the application so it can be edited, or perhaps it is available in the
> registry. I don't do much with Delphi lately and I'm rather rusty, and
> want to maintain at least a modicum of familiarity and competence.
>
> Thanks,
>
> Paul
This should work in D5. (I do not know if this works with D4)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Registry;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
FIniFile: TRegIniFile;
end;
var
Form1: TForm1;
implementation
uses ShlObj, FileCtrl;
var lg_StartFolder: String;
{$R *.DFM}
const
SECTION = 'Sample';
procedure TForm1.FormCreate(Sender: TObject);
begin
FIniFile := TRegIniFile.Create('Sample Registry');
Edit1.Text := FIniFile.ReadString(SECTION, 'HandleFolder', 'No folder
selected');
end;
function BrowseForFolderCallBack(Wnd: HWND; uMsg: UINT; lParam, lpData:
LPARAM): Integer stdcall;
begin
if uMsg = BFFM_INITIALIZED then
SendMessage(Wnd,BFFM_SETSELECTION, 1, Integer(@lg_StartFolder[1]));
result := 0;
end;
function BrowseForFolder(const browseTitle: String; const initialFolder:
String =''): String;
var
browse_info: TBrowseInfo;
folder: array[0..MAX_PATH] of char;
find_context: PItemIDList;
begin
FillChar(browse_info,SizeOf(browse_info),#0);
lg_StartFolder := initialFolder;
browse_info.pszDisplayName := @folder[0];
browse_info.lpszTitle := PChar(browseTitle);
browse_info.ulFlags := BIF_RETURNONLYFSDIRS;
browse_info.lpfn := BrowseForFolderCallBack;
find_context := SHBrowseForFolder(browse_info);
if Assigned(find_context) then
begin
if SHGetPathFromIDList(find_context,folder) then
result := folder
else
result := '';
end
else
result := '';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := BrowseForFolder('Select folder');
if (DirectoryExists(Edit1.Text)) then
FIniFile.WriteString(SECTION, 'HandleFolder', Edit1.Text);
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
Cleanup: TRegistry;
key: string;
begin
key := FIniFile.FileName;
FIniFile.Free;
// make sure we don't leave junk in the registry behind.
Cleanup := TRegistry.Create;
try
Cleanup.DeleteKey(key);
finally
Cleanup.Free;
end;
end;
end.
// EOF
Back to comp.lang.pascal.delphi.misc | Previous | Next — Previous in thread | Find similar
Open dialog to display directory only (D4) "P E Schoen" <paul@pstech-inc.com> - 2015-07-20 17:15 -0400
Re: Open dialog to display directory only (D4) "Peter Below (TeamB)" <none@address.invalid> - 2015-07-21 17:38 +0000
Re: Open dialog to display directory only (D4) "Faxe" <Faxe@invalid.invalid> - 2015-07-21 18:12 +0000
Re: Open dialog to display directory only (D4) "P E Schoen" <paul@pstech-inc.com> - 2015-07-25 23:59 -0400
Re: Open dialog to display directory only (D4) Richard <nospam@localhost.nil> - 2015-07-22 19:19 +0200
csiph-web