Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi extract subdirectory name (https://www.delphipraxis.net/92427-extract-subdirectory-name.html)

mijack 19. Mai 2007 16:09


extract subdirectory name
 
let's suppose this :


Delphi-Quellcode:
[b]Label1.caption :='c:\Folfer1\file1'[/b]

i want to dispaly :

label2.caption:=File1    label3.caption:=' nothing to display '


[b]Label1.caption :='c:\Folder1\Folder2\file1'[/b]

i want to dispaly :

label2.caption:=File1 label3.caption:='repertoire2\'

Der_Unwissende 19. Mai 2007 16:19

Re: extract subdirectory name
 
Hi,
what about using some kind of Tokenizer (e.g. split). Just split the input by the PathSeperator, which will return a Stringlist containing one entry per directory (and of course the file). So the first entry will be the drive, the second one contains the "main"-directory, the last one will contain the fileName, the entrys beetween the second and last one are subfolders.

Regards Der Unwissende

mijack 19. Mai 2007 16:37

Re: extract subdirectory name
 
Thank you Der_Unwissende

Could you please give me an Exemple .

Hawkeye219 19. Mai 2007 16:48

Re: extract subdirectory name
 
Hi mijack,

try a combination of Delphi-Referenz durchsuchenExtractRelativePath and Delphi-Referenz durchsuchenExtractFilePath:

Delphi-Quellcode:
var
  s, t : string;
begin
  s := 'c:\Folder1\file1';
  t := ExtractRelativePath('c:\Folder1\', ExtractFilePath(s)); // -> t = ''

  s := 'c:\Folder1\Folder2\file1';
  t := ExtractRelativePath('c:\Folder1\', ExtractFilePath(s)); // -> t = 'Folder2\'
end;
Regards


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:00 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz