function GetFileName(str:string):string
var
i:Integer
x,y:string
begin
x:=ExtractFileName(str) //取文件名+扩展名,不包含文件路径
y:=ExtractFileExt(str) //取文件的扩展名
i:=Pos(y,x) //确定扩展名所在位置
if i<>0 then
begin
Result:=Copy(x,0,i-1) //复制文件名,忽略掉后面的扩展名
end
else begin
Result:=''
end
end
使用的时候直接这样就行
GetFileName(TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename)
输出:科比
用FindFirst,FindNext,FindCloseprocedure SearchFileEx(const Dir, Ext: stringFiles: TStrings)
var
Found: TSearchRec
i: integer
Dirs: TStrings
Finished: integer
StopSearch: Boolean
begin
StopSearch := False
Dirs := TStringList.Create
Finished := FindFirst(Dir + '*.*', 63, Found)
while (Finished = 0) and not (StopSearch) do
begin
if (Found.Name <>'.') then
begin
if (Found.Attr and faDirectory) = faDirectory then
Dirs.Add(Dir + Found.Name)
else
if Pos(UpperCase(Ext), UpperCase(Found.Name)) >0 then
Files.Add(Dir + Found.Name)
end
Finished := FindNext(Found)
end
FindClose(Found)
if not StopSearch then
for i := 0 to Dirs.Count - 1 do
SearchFileEx(Dirs[i], Ext, Files)
Dirs.Free
end
3
procedure FindSubDir(DirName: stringFileString: TStrings)
var
searchRec: TsearchRec
begin
//找出所有下级子目录。
if (FindFirst(DirName + '*.*', faDirectory, SearchRec) = 0) then
begin
if IsValidDir(SearchRec) then
FileString.Add(DirName + SearchRec.Name)
while (FindNext(SearchRec) = 0) do
begin
if IsValidDir(SearchRec) then
FileString.Add(DirName + SearchRec.Name)
end
end
FindClose(SearchRec)
end
function IsValidDir(SearchRec: TSearchRec): Boolean
begin
if (SearchRec.Attr = 16) and (SearchRec.Name <>'.') and (SearchRec.Name <>'..') then
Result := True
else
Result := False
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)