Another sort and reorder question
Posted: 19 Mar 2018 16:41
Hi, I have another sort and reorder question. I apologize up front for the lengthy post. After some lost sleep and fried brain cells, I was finally able to come up with a solution, but it's probably not the most elegant or tightest coding...for sure. Maybe you can point me in the right direction for a more direct method. I have a $build_data list built within a script, but for ease of testing I made in a heredoc in the last code block.My goal is to have the folders all sorted/matched or grouped together and also have the current view ($view_cid) as the first one in the list for each folder group.
Formatlist will give me the folders nicely sorted.This is the desired result below. As in my previous reorder problem here viewtopic.php?f=3&t=18572, the $view_cid can change (instead of 308 it could be 307 etc). I want $view_cid as the lead view in each folder group, but I don't care about the order of the remaining items.From there, the method I came up with involves first grouping the same folders together and then rearranging and place the folder with in the specified view first. After this is done for each folder grouping, the groupings are combined. Seems like a bunch of work...it is fast enough though. Within the script I do have another variable of the $paths (in this case it would be 4 paths also <crlf> separated).Any ideas or thoughts on a possibly more direct method? Thanks.
Code: Select all
F:\Wallpaper\|307
F:\Wallpaper\Colorado\|308
F:\Wallpaper\Colorado\June\deep\|307
F:\Wallpaper\|306
F:\Wallpaper\|308
F:\Wallpaper\Colorado\June\deep\|308
F:\Wallpaper\Colorado\June\|306
F:\Wallpaper\Colorado\|306
F:\Wallpaper\Colorado\|307
F:\Wallpaper\Colorado\June\|307
F:\Wallpaper\Colorado\June\deep\|306
F:\Wallpaper\Colorado\June\|308
Formatlist will give me the folders nicely sorted.
Code: Select all
$build_data = formatlist($build_data, "se", "<crlf>");Code: Select all
F:\Wallpaper\|306
F:\Wallpaper\|307
F:\Wallpaper\|308
F:\Wallpaper\Colorado\|306
F:\Wallpaper\Colorado\|307
F:\Wallpaper\Colorado\|308
F:\Wallpaper\Colorado\June\|306
F:\Wallpaper\Colorado\June\|307
F:\Wallpaper\Colorado\June\|308
F:\Wallpaper\Colorado\June\deep\|306
F:\Wallpaper\Colorado\June\deep\|307
F:\Wallpaper\Colorado\June\deep\|308
Code: Select all
F:\Wallpaper\|308
F:\Wallpaper\|306
F:\Wallpaper\|307
F:\Wallpaper\Colorado\|308
F:\Wallpaper\Colorado\|306
F:\Wallpaper\Colorado\|307
F:\Wallpaper\Colorado\June\|308
F:\Wallpaper\Colorado\June\|306
F:\Wallpaper\Colorado\June\|307
F:\Wallpaper\Colorado\June\deep\|308
F:\Wallpaper\Colorado\June\deep\|306
F:\Wallpaper\Colorado\June\deep\|307Code: Select all
$build_data=<<<DAT
F:\Wallpaper\|307
F:\Wallpaper\Colorado\|308
F:\Wallpaper\Colorado\June\deep\|307
F:\Wallpaper\|306
F:\Wallpaper\|308
F:\Wallpaper\Colorado\June\deep\|308
F:\Wallpaper\Colorado\June\|306
F:\Wallpaper\Colorado\|306
F:\Wallpaper\Colorado\|307
F:\Wallpaper\Colorado\June\|307
F:\Wallpaper\Colorado\June\deep\|306
F:\Wallpaper\Colorado\June\|308
DAT;
$view_cid = "308";
$build_data = formatlist($build_data, "se", "<crlf>");
$paths = "F:\Wallpaper\<crlf>F:\Wallpaper\Colorado<crlf>F:\Wallpaper\Colorado\June<crlf>F:\Wallpaper\Colorado\June\deep";
echo $build_data;
$i = 1;$New_Build_Data = "";
foreach($path, $paths, "<crlf>","e") {
if(substr($path, -1) != "\") {$path = $path . "\";}
$new_build_i = "";$new_pathlist_i = "";
foreach($data, $build_data,"<crlf>", "e") {
if($path LikeI gettoken($data, "1", "|")) {
$new_build_i = $new_build_i . $data . "<crlf>";
}
else {continue; }
$new_viewline_i = formatlist($new_build_i, "nf", "<crlf>", '*|' . $view_cid);
$new_pathlist_i = $new_viewline_i . "<crlf>" . replace($new_build_i, $new_viewline_i);
// $new_pathlist_i = Reorder($new_pathlist_i, $new_viewline_i); or use highend's Reorder function
}
echo NewPathList_$i<crlf 2>$new_pathlist_i;
$New_Build_Data = $New_Build_Data . $new_pathlist_i;
$i++;
}
$build_data = formatlist($New_Build_Data, "e", "<crlf>");
echo $build_data;