Home > Back-end >  Delphi, excuse me how to get the path to the file according to the specified period of cut open
Delphi, excuse me how to get the path to the file according to the specified period of cut open

Time:10-13

As title, such as:
I get to the file path is c: \ program files \ copia \ cbps8 \ etc \ version ini
I now want to path cut open, only take "etc \ version ini", excuse me everybody, is there any simple way to achieve?

CodePudding user response:

Themselves from after the second slash, with pos

CodePudding user response:

 function MyGetPath (Path: string; PathNum: Integer) : string; 
Var
I: Integer;
TmpPath: string;
The begin
Result:=ExtractFileName (Path);
TmpPath:=Path;
For I:=1 to PathNum do
The begin
TmpPath:=ExtractFileDir (tmpPath);
Result:=Format (' % s \ % s', [ExtractFileName (tmpPath), the Result]);
end;
end;

Procedure TForm1. Button2Click (Sender: TObject);
The begin
ShowMessage (MyGetPath (' c: \ program files \ copia \ cbps8 \ etc \ version ini ', 1));
//MyGetPath (the full path, with several layers of directory).
end;

CodePudding user response:

 var 
S: a string;
I, J: Integer;
The begin
S:='c: \ program files \ copia \ cbps8 \ etc \ version ini';
J:=1;
For I:=Length (s) downto 1 do
The begin
If [I]='\' s then
If J=1 then Inc (J)
The else
The begin
Showmessage (copy (s, I + 1, maxint));
Break
end;
end;
end;