 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
HarryS Guest
|
Posted: Fri Jan 07, 2005 3:30 pm Post subject: Short vs. Long filenames |
|
|
I'm doing something like this:
procedure TDriveNDlg.FormCreate(Sender: TObject);
var CurrentDir : string;
begin
GetDir(0,CurrentDir);
DriveNDlg.Edit1.Text := CurrentDir;
end;
Why does the Edit1 text show the short filenames rather than the long
filenames, i.e., "C:DOCUME~1HARRY~1LOCALS~1Temp"?
Thanks,
Harry
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Fri Jan 07, 2005 4:28 pm Post subject: Re: Short vs. Long filenames |
|
|
On Fri, 07 Jan 2005 15:30:11 GMT, "HarryS" <hsom-spam- (AT) showmepro (DOT) com>
waffled on about something:
| Quote: | I'm doing something like this:
procedure TDriveNDlg.FormCreate(Sender: TObject);
var CurrentDir : string;
begin
GetDir(0,CurrentDir);
DriveNDlg.Edit1.Text := CurrentDir;
end;
Why does the Edit1 text show the short filenames rather than the long
filenames, i.e., "C:DOCUME~1HARRY~1LOCALS~1Temp"?
Thanks,
Harry
|
What version of Delphi/Windows are you using?
In D5 on Win2k/XP it returns the long filename.
In D5 the GetDir routine is a very simple wrapper round the
GetCurrentDirectory WinAPI call, so I suspect you must be using an OS
which doesn't natively (i.e. internally) work with long filenames... I
think that's 95/98 (maybe ME)
This is the D5 source for GetDir.
procedure GetDir(D: Byte; var S: string);
var
Drive: array[0..3] of Char;
DirBuf, SaveBuf: array[0..259] of Char;
begin
if D <> 0 then
begin
Drive[0] := Chr(D + Ord('A') - 1);
Drive[1] := ':';
Drive[2] := #0;
GetCurrentDirectory(SizeOf(SaveBuf), SaveBuf);
SetCurrentDirectory(Drive);
end;
GetCurrentDirectory(SizeOf(DirBuf), DirBuf);
if D <> 0 then SetCurrentDirectory(SaveBuf);
S := DirBuf;
end;
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
HarryS Guest
|
Posted: Fri Jan 07, 2005 5:36 pm Post subject: Re: Short vs. Long filenames |
|
|
Thanks Dodgy,
I'm using Delphi 7 on XP Home.
I think I've determined what is causing this. The snippet you see below is
from an installation program (setup.exe). I put setup.exe, along with the
rest of the distribution files, in a self-extracting archive that
automatically runs setup.exe. The self-extractor creates a temporary
directory, copies all of the files into the directory, then runs setup.exe.
For some reason, this temporary directory displays in the edit control
mentioned below in setup.exe with the path displayed as short filenames.
When setup.exe is run standalone (not from the self-extractor), the edit
control displays the long filenames returned by GetDir. I tried two
different utilities for creating the self-extracting archive and they both
create the same effect.
Harry
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> wrote
| Quote: | On Fri, 07 Jan 2005 15:30:11 GMT, "HarryS" <hsom-spam- (AT) showmepro (DOT) com
waffled on about something:
I'm doing something like this:
procedure TDriveNDlg.FormCreate(Sender: TObject);
var CurrentDir : string;
begin
GetDir(0,CurrentDir);
DriveNDlg.Edit1.Text := CurrentDir;
end;
Why does the Edit1 text show the short filenames rather than the long
filenames, i.e., "C:DOCUME~1HARRY~1LOCALS~1Temp"?
Thanks,
Harry
What version of Delphi/Windows are you using?
In D5 on Win2k/XP it returns the long filename.
In D5 the GetDir routine is a very simple wrapper round the
GetCurrentDirectory WinAPI call, so I suspect you must be using an OS
which doesn't natively (i.e. internally) work with long filenames... I
think that's 95/98 (maybe ME)
This is the D5 source for GetDir.
procedure GetDir(D: Byte; var S: string);
var
Drive: array[0..3] of Char;
DirBuf, SaveBuf: array[0..259] of Char;
begin
if D <> 0 then
begin
Drive[0] := Chr(D + Ord('A') - 1);
Drive[1] := ':';
Drive[2] := #0;
GetCurrentDirectory(SizeOf(SaveBuf), SaveBuf);
SetCurrentDirectory(Drive);
end;
GetCurrentDirectory(SizeOf(DirBuf), DirBuf);
if D <> 0 then SetCurrentDirectory(SaveBuf);
S := DirBuf;
end;
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Fri Jan 07, 2005 6:27 pm Post subject: Re: Short vs. Long filenames |
|
|
On Fri, 07 Jan 2005 17:36:52 GMT, "HarryS" <hsom-spam- (AT) showmepro (DOT) com>
waffled on about something:
| Quote: | Thanks Dodgy,
I'm using Delphi 7 on XP Home.
I think I've determined what is causing this. The snippet you see below is
from an installation program (setup.exe). I put setup.exe, along with the
rest of the distribution files, in a self-extracting archive that
automatically runs setup.exe. The self-extractor creates a temporary
directory, copies all of the files into the directory, then runs setup.exe.
For some reason, this temporary directory displays in the edit control
mentioned below in setup.exe with the path displayed as short filenames.
When setup.exe is run standalone (not from the self-extractor), the edit
control displays the long filenames returned by GetDir. I tried two
different utilities for creating the self-extracting archive and they both
create the same effect.
Harry
|
That's very odd indeed!
I must admit I've never tried what you describe, I wonder if one of
the resident guru's can shed some light on this.
/me steps aside
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Jamie Guest
|
Posted: Sat Jan 08, 2005 7:57 pm Post subject: Re: Short vs. Long filenames |
|
|
HarryS wrote:
| Quote: | I'm doing something like this:
procedure TDriveNDlg.FormCreate(Sender: TObject);
var CurrentDir : string;
begin
GetDir(0,CurrentDir);
DriveNDlg.Edit1.Text := CurrentDir;
end;
Why does the Edit1 text show the short filenames rather than the long
filenames, i.e., "C:DOCUME~1HARRY~1LOCALS~1Temp"?
Thanks,
Harry
you can use the GetLongPathName function .. |
it will convert the name to the long type, it will
also accept a path that is already converted to
a long type in the event that your on an OS that
already does that like the W2k and up et.c.
you must be working with a 9x box ?
P.S.
you may need to import this function from the kernel32.dll if
your using an older compiler.
function GetLongPathName(ShortName,LongName:Pchar;ccbuffer:Dword):Dword;
stdcall external 'kernel32.dll' name 'GetLongPathNameA';
you could use the W version if your working with UNicode.
Example below.
procedure TForm1.Button1Click(Sender: TObject);
var
S,LS,SS:String;
MyIndex:Pchar;
begin
ChDir('C:Documents and Settings');
GetDir(0,S);
SetLength(SS,1000);
SetLength(SS, GetShortPathName(Pchar(S),Pchar(SS),1000));
MessageDlg(SS,mterror,[mbok],0);
// now convert it back
SetLength(LS,1000);
SetLength(LS,GetLongPathName(Pchar(SS),Pchar(LS),1000));
MessageDlg(LS,mtError,[mbok],0);
end;
the GetLongPathName will simply return back the same string
if the string you give is already a long path, this resolves
the problem of knowing when to use the function.
|
|
| Back to top |
|
 |
HarryS Guest
|
Posted: Tue Jan 11, 2005 3:16 pm Post subject: Re: Short vs. Long filenames |
|
|
Thanks Jaime,
These self-extraction utilities must force 8.3 format for some reason. One
of them (iexpress.exe) even gives the option of storing the long filenames
in the self-extracting file, but for some reason it doesn't follow thru to
the setup.exe that runs from within the self-extracting file. If setup.exe
is run without putting it in the self-extracting file, it displays long
filenames. It apparently doesn't make any difference which operating system
it's running on. I'm seeing this on XP Home and XP Pro.
Your suggestion works great.
Thanks,
Harry
"Jamie" <jamie_5_not_valid_after_5_Please (AT) charter (DOT) net> wrote
| Quote: | HarryS wrote:
I'm doing something like this:
procedure TDriveNDlg.FormCreate(Sender: TObject);
var CurrentDir : string;
begin
GetDir(0,CurrentDir);
DriveNDlg.Edit1.Text := CurrentDir;
end;
Why does the Edit1 text show the short filenames rather than the long
filenames, i.e., "C:DOCUME~1HARRY~1LOCALS~1Temp"?
Thanks,
Harry
you can use the GetLongPathName function ..
it will convert the name to the long type, it will
also accept a path that is already converted to
a long type in the event that your on an OS that
already does that like the W2k and up et.c.
you must be working with a 9x box ?
P.S.
you may need to import this function from the kernel32.dll if
your using an older compiler.
function GetLongPathName(ShortName,LongName:Pchar;ccbuffer:Dword):Dword;
stdcall external 'kernel32.dll' name 'GetLongPathNameA';
you could use the W version if your working with UNicode.
Example below.
procedure TForm1.Button1Click(Sender: TObject);
var
S,LS,SS:String;
MyIndex:Pchar;
begin
ChDir('C:Documents and Settings');
GetDir(0,S);
SetLength(SS,1000);
SetLength(SS, GetShortPathName(Pchar(S),Pchar(SS),1000));
MessageDlg(SS,mterror,[mbok],0);
// now convert it back
SetLength(LS,1000);
SetLength(LS,GetLongPathName(Pchar(SS),Pchar(LS),1000));
MessageDlg(LS,mtError,[mbok],0);
end;
the GetLongPathName will simply return back the same string
if the string you give is already a long path, this resolves
the problem of knowing when to use the function.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|