How to extract one folder name from a folder tree in TShellTreeView lazarus / 16-Databases ---------------------------------------------------------------------- Gizmo · 2021-03-18 18:04 What is the easiest method of obtaining the portion of a full path that represents a specific folder as selected by the user in TShellTreeView, and all of the folders below it? For example, given the following path : C:\ToplevelFolder\SubFolder1\Subfolder2\Subfolder3\ Lets say the user selects "Subfolder2", if I want to "get" (extract and store in a variable) "Subfolder2", but then also have (not lose) Subfolder2\Subfolder3, is there a given means to do that natively with a specific function already? So what I want is Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i strSelectedFolder :=  TShellTreeView.Path; // but not the full path - just the bit the user has selected, i.e. 'Subfolder2';strFullFolderFromSelection := strSelectedFolder + // 'Subfolder3' etc;  So I want lose (discard) C:\TopLevelFolder\SubFolder1 but keep SubFolder2 downwards. I am using ExtractFileDir on values obtained via TShellTreeView which gives me the full folder path as a string, but if I just want a given folder and its child folders from that string to pass to another variable, how best to do that? I did wonder if ExtractRelativePath might be the ticket, but that appears to want to copy folders, unless I mis-understand. ---------------------------------------------------------------------- wp · 2021-03-18 18:30 I think you should seek for the subfolders at file level (FindFirst/FindNext) because the tree loads a subfolder only when it is expanded. ---------------------------------------------------------------------- winni · 2021-03-18 18:40 Hi! Count the DirectorySeparator from the end of the path. When you reach the desired number (here: 2) copy the part of the path or delete the leadig part.Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  function LastPartPath(path : string;  NumSep: integer) : string;var i : integer;      count: integer=0; beginresult := '';for i := lengh(path) downto 1 do   begin  if path[i] = directorySeparator then  begin  inc(count);  if count = numSep then       begin       result := copy (path,i+1,maxint);       exit;       end; // numSep end; // if  end; // iend; Winni