请问给定一个fillname有没有直接函数可以取其盘符?好像getdrive和getdrivename是这种功能,可是它们在哪个单元呢?(2分)

  • 主题发起人 主题发起人 lkdbdlkq
  • 开始时间 开始时间
L

lkdbdlkq

Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是DELPHI 7,为什么找不到这个函数?错误提示:[Error] Unit1.pas(126): Undeclared identifier: 'getdrivename'
 
procedure TForm1.FormCreate(Sender: TObject);
var
buf:array [0..MAX_PATH-1] of char;
m_Result:Integer;
i:Integer;
str_temp:string;
begin
m_Result:=GetLogicalDriveStrings(MAX_PATH,buf);
for i:=0 to (m_Result div 4) do
begin
str_temp:=string(buf[i*4]+buf[i*4+1]+buf[i*4+2]);
ListBox1.Items.Add(str_temp);
end;
end;
 
Copy(ExtracFilePath(Application.ExeName),1,2);
 
如果你给的文件名为全名的话,我觉得可以自己写子程序。
if Pos('//',sFileName)>0 then
showmessage('网络')
else
begin
iPos:=Pos(':/',sFileName);
sDriver:=Copy(sFileName,1,iPos-1);
end;
 
Delphi有这个函数的:
function ExtractFileDrive(const FileName: string): string;

Returns the drive portion of a file name.

Unit

SysUtils

Category

file name utilities

Delphi syntax:

function ExtractFileDrive(const FileName: string): string;

C++ syntax:

extern PACKAGE AnsiString __fastcall ExtractFileDrive(const AnsiString FileName);

Description

On Windows, ExtractFileDrive returns a string containing the drive portion of a fully qualified path name for the file passed in the FileName. For file names with drive letters, the result is in the form ?<drive>'? For file names with a UNC path the result is in the form ?//<servername>/<sharename>'? If the given path contains neither style of path prefix, the result is an empty string.
On Linux, ExtractFileDrive always returns a zero-length string.
 
Copy(ExtracFilePath(Application.ExeName),1,2);
李翔鹏的回答最一针见血;
顶!!!
 
多谢,记错了函数名,我要的是这个,可惜我的分太少了,只有可怜的这么一点。。。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
871
import
I
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部