Еще решение
Совсем забыли про регулярки...
Код:
uses
RegularExpressions;
...
function GetPartPathOfFile(PathFile: String; Psn: Byte): String;
var
Match: TMatchCollection;
Reg: TRegEx;
I: Byte;
Res: String;
begin
Reg := TRegEx.Create('[^\\]+');
if Reg.IsMatch(PathFile) then
begin
Match := Reg.Matches(PathFile, '[^\\]+', [roIgnoreCase]);
I := Psn;
while I <> Match.Count do
begin
Res := Res + Match.Item[i].Value + '\';
Inc(I);
end;
Delete(Res, Length(Res), 1);
end;
Result := Res;
end;
Пример вызова (2-ой параметр означает с какого обратного слеша вернуть строку)
Код:
Edit1.Text := GetPartPathOfFile('C\:папка1\папка2\файл.txt', 2);
__________________
Всегда пишите код так, будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете.
|