全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2515
推到 Plurk!
推到 Facebook!

如何轉換長檔名與DOS檔名?

 
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-05-03 19:50:22 IP:61.219.xxx.xxx 未訂閱
如何轉換長檔名與DOS檔名?
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;    type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.DFM}     function GetShortName(sLongName : string) : string;
 var
   sShortName    : string;
   nShortNameLen : integer;
 begin
   SetLength(sShortName, MAX_PATH);       nShortNameLen := GetShortPathName(PChar(sLongName),
                      PChar(sShortName), MAX_PATH-1);       if nShortNameLen = 0 then
   begin
     { handle errors... }
   end;       SetLength(sShortName, nShortNameLen);       Result := sShortName;
 end;     function GetLongName_(sShortName : string; var bError : boolean) : string;
 var
   bAddSlash : boolean;
   SearchRec : TSearchRec;
   nStrLen   : integer;
 begin
   bError    := False;
   Result    := sShortName;
   nStrLen   := Length(sShortName);
   bAddSlash := False;       if sShortName[nStrLen] = '\' then
   begin
     bAddSlash := True;
     SetLength(sShortName, nStrLen-1);
     dec(nStrLen);
   end;
   
   if((nStrLen-Length(ExtractFileDrive(sShortName))) > 0) then
   begin
     if FindFirst(sShortName, faAnyFile, SearchRec) = 0 then
     begin
       Result := ExtractFilePath(sShortName)   SearchRec.name;
       if bAddSlash then
       begin
         Result := Result   '\';
       end;
     end
     else
     begin
       // handle errors...       bError := True;
     end;
     FindClose(SearchRec);
   end;
 end;     function GetLongName(sShortName : string) : string;
 var
   s      : string;
   p      : integer;
   bError : boolean;
 begin
   Result := sShortName;
   
   s := '';
   p := Pos('\', sShortName);
   while(p > 0)do
   begin
     s := GetLongName_(s   Copy(sShortName, 1, p), bError);
     Delete(sShortName, 1, p);
     p := Pos('\', sShortName);         if(bError)then
       Exit;
   end;
   if sShortName <> '' then
   begin
     s := GetLongName_(s   sShortName, bError);
     if bError then
       Exit;
   end;
   Result := s;
 end;    procedure TForm1.Button1Click(Sender: TObject);
begin
  caption:=GetShortName(edit1.text);
end;    procedure TForm1.Button2Click(Sender: TObject);
begin
  caption:=GetLongName(edit2.text);    end;    end.    
~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
系統時間:2024-05-03 10:29:12
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!