Discussion:
Open dialog to display directory only (D4)
(too old to reply)
P E Schoen
2015-07-20 21:15:49 UTC
Permalink
Raw Message
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
Peter Below (TeamB)
2015-07-21 17:38:59 UTC
Permalink
Raw Message
Post by P E Schoen
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
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.
If you use a TOpenDialog component you can set its InitialDir property
the directory you want the dialog to open in. The Options property
allows you to configure the behaviour of the dialog, e.g. whether it
should allow the user to select more than one file. You call the
dialog's Execute method to show it, and once it is up the user can
navigate around the file system at will. If the directory you specified
at design-time does not exist on the target machine the dialog will
open at a defaul location. Of course you can also set InitialDir at
runtime, e.g. to the folder the user last visited and which you
remembered in a settings file.
--
Peter Below (TeamB)
Faxe
2015-07-21 18:12:55 UTC
Permalink
Raw Message
Post by Peter Below (TeamB)
Post by P E Schoen
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
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.
If you use a TOpenDialog component you can set its InitialDir property
the directory you want the dialog to open in. The Options property
allows you to configure the behaviour of the dialog, e.g. whether it
should allow the user to select more than one file. You call the
dialog's Execute method to show it, and once it is up the user can
navigate around the file system at will. If the directory you
specified at design-time does not exist on the target machine the
dialog will open at a defaul location. Of course you can also set
InitialDir at runtime, e.g. to the folder the user last visited and
which you remembered in a settings file.
Maybe the use of ShBrowseForFolder is the better way with older Delphi.

Here is a short description:
http://delphi.about.com/od/windowsshellapi/l/aa070400a.htm
P E Schoen
2015-07-26 03:59:54 UTC
Permalink
Raw Message
Post by Faxe
Maybe the use of ShBrowseForFolder is the better way with older Delphi.
http://delphi.about.com/od/windowsshellapi/l/aa070400a.htm
Those were some good suggestions. I went ahead and coded the project using a
hard-coded location for the folders and files I wanted to "ZAP", and I was
able to move and delete the duplicate files in the Junk Email folder. But I
found that mucking with the files in Windows Live Mail causes problems so I
may need to do something different.

Probably I can just use WLM to move most of the files to another folder and
copy them elsewhere and then delete the duplicates and put the remaining
files in a compressed folder for backup. But, really, I just need to save
important emails as I receive and send them, and stop thinking that I might
someday get the time to read the others that usually have limited interest
and are irrelevant after a couple of weeks. I get about 100/day so they pile
up quickly!

I got some helpful information in the Tek-Tips forum:

OpenDialog1.InitialDir := GetCSIDLPath(CSIDL_LOCAL_APPDATA) +
'\Microsoft\Windows Live Mail\';

http://www.tek-tips.com/viewthread.cfm?qid=1752538

Thanks for the help. At least I know that this newsgroup is still active and
useful :)

Paul

Richard
2015-07-22 17:19:19 UTC
Permalink
Raw Message
Post by P E Schoen
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
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
Loading...