Create alphabetical list of multiple folders and subfolders on separate drives

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

I'm trying to make a script that will create an alphabetical list of all my movie files using just their folder names. They are stored in multiple Movies folders on separate drives, with each movie in its own folder (name and (year)) and movies belonging to a franchise are in a franchise folder (the uppercase lines in the example below). This is an example of the folder structure:

Q:\Movies
	A Haunting in Venice (2023)
	A Minecraft Movie (2025)
	ALIEN
		Alien (1979)
		Alien 3 (1992)
		Alien Covenant (2017)
		Alien Resurrection (1997)
		Alien Romulus (2024)
	Dawn Of The Dead (2004)
	Dead Man's Folly (1986)
	DEADPOOL
		Deadpool (2016)
		Deadpool 2 (2018)
	Deadwood, The Movie (2019)
	Death Becomes Her (1992)


Using folderreport, I've manged to get a file that has all the movie folders in it. Obviously, writing good scripts is not my really my strength because I know it's probably not as clean as it could be but it's what I came up with. This is the code:

Code: Select all

$reportfile = "C:\Users\delee\MEGA\Media\_Media File Lists\All Movies.txt";
	$folder1 = folderreport("tree:{name}", "r", "Q:\Movies", "r", , , 1);
	$folder2 = folderreport("tree:{name}", "r", "R:\Movies", "r", , , 1);
	$folder3 = folderreport("tree:{name}", "r", "Y:\Movies", "r", , , 1);
	$list = "$folder1$folder2$folder3";
	
	$search1 = "Q:\Movies<crlf>";
	$replace1 = "";
	$newlist1 = replace($list, $search1, $replace1);
	
	$search2 = "R:\Movies<crlf>";
	$replace2 = "";
	$newlist2 = replace($newlist1, $search2, $replace2);
	
	$search3 = "Y:\Movies<crlf>";
	$replace3 = "";
	$newlist3 = replace($newlist2, $search3, $replace3);
	
	writefile($reportfile, $newlist3);
It works, however, each drive is listed one after the other and I can't figure out how to sort it. I would like to sort it and maintain the franchise/movies folders as they are but if it's easier, the franchise lines could be removed and just include the movie folders.

I also made a similar script using dirs:{name} instead of tree:{name} which I could sort but then the franchise folders just became part of the list. This is the code:

Code: Select all

$reportfile = "C:\Users\delee\MEGA\Media\_Media File Lists\All Movies.txt";
	$folder1 = folderreport("dirs:{name}", "r", "Q:\Movies", "r", , , 1);
	$folder2 = folderreport("dirs:{name}", "r", "R:\Movies", "r", , , 1);
	$folder3 = folderreport("dirs:{name}", "r", "Y:\Movies", "r", , , 1);
	$list = "$folder1$folder2$folder3";
	writefile($reportfile, formatlist("$list", "se", "<crlf>"));
Any help with either script (or a completely new one) would be greatly appreciated.
Windows 10 Pro 22H2

jupe
Posts: 3462
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by jupe »

Below is one alternative way that I think would achieve your goal, I just left it as a popup dialog output, you can change it yourself to writefile if you think it is suitable.

Code: Select all

  $d = quicksearch("/d", "Q:\Movies|R:\Movies|Y:\Movies");
  $d = formatlist(regexreplace($d, "^.:.+?\\"), s, <crlf>);
  $d = regexreplace($d, "^.+\\", <space 2>);
  text $d;

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

jupe wrote: 29 Mar 2026 05:21 Below is one alternative way that I think would achieve your goal, I just left it as a popup dialog output, you can change it yourself to writefile if you think it is suitable.

Code: Select all

  $d = quicksearch("/d", "Q:\Movies|R:\Movies|Y:\Movies");
  $d = formatlist(regexreplace($d, "^.:.+?\\"), s, <crlf>);
  $d = regexreplace($d, "^.+\\", <space 2>);
  text $d;
Oh wow! Thanks. It almost works. There's an issue with some titles that share (or start with) the same name as a franchise folder and are being sorted below the franchise line.

For example:
Captain America (1990) is not in the CAPTAIN AMERICA franchise folder:

CAPTAIN AMERICA
Captain America (1990)
  Captain America Civil War (2016)
  Captain America The First Avenger (2011)
  Captain America The Winter Soldier (2014)


Cirque Du Soleil Worlds Away (2012) is not in the CIRQUE DU SOLEIL folder:

CIRQUE DU SOLEIL
Cirque Du Soleil Worlds Away (2012)
  O (2017)
  Toruk, The First Flight (2016)
Windows 10 Pro 22H2

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by highend »

Then throw away all entries with folder names that don’t contain a year via regex?

Code: Select all

$d = regexreplace($d, "^(?!.*\(\d{4}\)).*(\r?\n|$)");
Otherwise you'll have to do it the hard way and resort the whole list by iterating over it...
One of my scripts helped you out? Please donate via Paypal

jupe
Posts: 3462
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by jupe »

Alternatively you could change the formatlist "s" on the second line to a "c" and I think that should resolve it, downside being that if you have any movies that start with a lowercase letter they'll be sorted at the very bottom, I think since there are not many of those you could just search and replace titlecase those before/after the sorting line.

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

jupe wrote: 29 Mar 2026 19:26 Alternatively you could change the formatlist "s" on the second line to a "c" and I think that should resolve it, downside being that if you have any movies that start with a lowercase letter they'll be sorted at the very bottom, I think since there are not many of those you could just search and replace titlecase those before/after the sorting line.
Thanks again. Replacing the 's' with a 'c' fixed that issue but created another one. The sorting still isn't right:

CAPTAIN AMERICA
  Captain America Civil War (2016)
  Captain America The First Avenger (2011)
  Captain America The Winter Soldier (2014)
CARS
  Cars (2006)
  Cars 2 (2011)
  Cars 3 (2017)
CATS & DOGS
  Cats & Dogs (2001)
  Cats & Dogs 3 Paws Unite (2020)
  Cats & Dogs, The Revenge Of Kitty Galore (2010)
CB4 (1993)
CIRQUE DU SOLEIL
  O (2017)
  Toruk, The First Flight (2016)
CLOUDY WITH A CHANCE OF MEATBALLS
  Cloudy With A Chance Of Meatballs (2009)
  Cloudy with a Chance of Meatballs 2 (2013)
Cabaret (1972)
Captain America (1990)
Captain Marvel (2019)
Captain Underpants, The First Epic Movie (2017)
Carrie (1976)


I managed to expand your script to do what I initially mentioned as an alternative option to remove the lines with the franchise folders.
Windows 10 Pro 22H2

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

highend wrote: 29 Mar 2026 11:09 Then throw away all entries with folder names that don’t contain a year

Code: Select all

$d = regexreplace($d, "^(?!.*\(\d{4}\)).*(\r?\n|$)");
Thank you! I had managed to get a working script to do that but this made it much better than mine.
Windows 10 Pro 22H2

jupe
Posts: 3462
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by jupe »

It's not that the sorting "isn't right" it is just different sorting, I did think though it might not suit you, anyway yeah if you now prefer it without the main franchise folders then the script becomes much more simple, something like this should do it (if you don't need the indenting either):

Code: Select all

text quicksearch("prop:#nosubs:2 /d", "Q:\Movies|R:\Movies|Y:\Movies", , "no");

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

jupe wrote: 29 Mar 2026 23:35

Code: Select all

text quicksearch("prop:#nosubs:2 /d", "Q:\Movies|R:\Movies|Y:\Movies", , "no");
I want to say how very appreciative I am of how much you've been helping me but I am having one hell of a time with this. I didn't mention in the beginning (because I thought I could do that bit myself) that some folders have a subfolder named subs. Obviously I don't want them in the list and I thought I would just remove those lines once I got a working script.

Using your last piece of code is perfect but, because you didn't know about the subs folders, any movie folder that belongs to a franchise, and contains a subs folder, is missing from the list (and subs is there instead). I'm assuming that's because of this: prop:#nosubs:2.

I went back over the previous code you and highend suggested and I did manage to get a script that creates a list with all the movie titles and not the franchise or subs folders. The only issue I have now is I can't get it to sort.

This is the code that gives me the list:

Code: Select all

  $d = quicksearch("/d", "Q:\Movies|R:\Movies|Y:\Movies");
  $d = regexreplace($d, "^.:.+?\\");
  $d = regexreplace($d, "^.+\\");
  $d = regexreplace($d, "^(?!.*\(\d{4}\)).*(\r?\n|$)");
  text $d;
I tried adding this before the text line to do the sorting: $d = formatlist($d, s, <crlf>); but it doesn't do anything.
Windows 10 Pro 22H2

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by highend »

Because

Code: Select all

$d = regexreplace($d, "^(?!.*\(\d{4}\)).*(\r?\n|$)");
can find zero-length matches which will turn the output in a non-<crlf> separated string
To remedy this just use this instead:

Code: Select all

$d = regexreplace($d, "^(?!.*\(\d{4}\)).*(\r?\n|$)", <crlf>);
Or make it easier and capture only video folders afterwards:

Code: Select all

  $d = quicksearch("/d", "C:\Movies1|C:\Movies2");
  $d = regexreplace($d, "^.:.+?\\");
  $d = regexreplace($d, "^.+\\");
  $d = formatlist($d, "s", <crlf>);
  $e = regexmatches($d, "^.+?\(\d{4}\)$", <crlf>);
  text $e;
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

highend wrote: 30 Mar 2026 09:22 Or make it easier and capture only video folders afterwards:

Code: Select all

  $d = quicksearch("/d", "C:\Movies1|C:\Movies2");
  $d = regexreplace($d, "^.:.+?\\");
  $d = regexreplace($d, "^.+\\");
  $d = formatlist($d, "s", <crlf>);
  $e = regexmatches($d, "^.+?\(\d{4}\)$", <crlf>);
  text $e;
Thank you so much!!!!!!! Perfect :appl:
Windows 10 Pro 22H2

jupe
Posts: 3462
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by jupe »

Ah the subs folders, I still think it could work as a one liner with a 'lil tweak, maybe

Code: Select all

text quicksearch(">\(\d{4}\) /d", "Q:\Movies|R:\Movies|Y:\Movies", , "no");
but anyway, glad you got it going.

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

jupe wrote: 30 Mar 2026 19:59 Ah the subs folders, I still think it could work as a one liner with a 'lil tweak, maybe

Code: Select all

text quicksearch(">\(\d{4}\) /d", "Q:\Movies|R:\Movies|Y:\Movies", , "no");
Amazing!!! A one-liner is so much better. Thank you!! :appl:
Windows 10 Pro 22H2

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by highend »

And a version that keeps the original layout without removing the non-video folders:

Code: Select all

    $locs = "Q:\Movies|R:\Movies|Y:\Movies";
    $dirs = quicksearch(">[^\subs] /d", $locs);
    $dirs = formatlist(regexreplace($dirs, "^.:.+?\\"), "s", <crlf>);
    $dirs = regexreplace($dirs, "^.+\\", <space 2>);
    
    $j        = 0;
    $log      = "";
    $cntItems = gettoken($dirs, "count", <crlf>);
    while ($i++ < $cntItems) {
        $line = gettoken($dirs, $i, <crlf>);

        // On each title, iterate items after it
        if (!regexmatches($line, "\(\d+\)")) {
            $j   = $i;
            $cnt = 0;
            // Loop over entries below the title line
            while ($j++ < $cntItems) {
                $curLine = gettoken($dirs, $j, <crlf>);
                // Break on an indented line
                if (regexmatches($curLine, "^\s")) { break; }
                $cnt++; // Count number of videos on root level
                $log .= $curLine . <crlf>;
            }
            $i += $cnt; // Let's jump over the processed lines
        }
        $log .= $line . <crlf>;
    }
    text $log;
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 675
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: Create alphabetical list of multiple folders and subfolders on separate drives

Post by kiwichick »

highend wrote: 04 Apr 2026 09:41 And a version that keeps the original layout without removing the non-video folders:

Code: Select all

    $locs = "Q:\Movies|R:\Movies|Y:\Movies";
    $dirs = quicksearch(">[^\subs] /d", $locs);
    $dirs = formatlist(regexreplace($dirs, "^.:.+?\\"), "s", <crlf>);
    $dirs = regexreplace($dirs, "^.+\\", <space 2>);
    
    $j        = 0;
    $log      = "";
    $cntItems = gettoken($dirs, "count", <crlf>);
    while ($i++ < $cntItems) {
        $line = gettoken($dirs, $i, <crlf>);

        // On each title, iterate items after it
        if (!regexmatches($line, "\(\d+\)")) {
            $j   = $i;
            $cnt = 0;
            // Loop over entries below the title line
            while ($j++ < $cntItems) {
                $curLine = gettoken($dirs, $j, <crlf>);
                // Break on an indented line
                if (regexmatches($curLine, "^\s")) { break; }
                $cnt++; // Count number of videos on root level
                $log .= $curLine . <crlf>;
            }
            $i += $cnt; // Let's jump over the processed lines
        }
        $log .= $line . <crlf>;
    }
    text $log;
Thanks, highend, I really appreciate the effort but, as with a previous code provided by @jupe, the sorting isn't right. And every line begins and ends with a single quote.

For example:
Captain America (1990) is not in the CAPTAIN AMERICA franchise folder:

'CAPTAIN AMERICA'
'Captain America (1990)'
' Captain America Civil War (2016)'
' Captain America The First Avenger (2011)'
' Captain America The Winter Soldier (2014)'

Cirque Du Soleil Worlds Away (2012) is not in the CIRQUE DU SOLEIL folder:

'CIRQUE DU SOLEIL'
'Cirque Du Soleil Worlds Away (2012)'
' O (2017)'
' Toruk, The First Flight (2016)'
Windows 10 Pro 22H2

Post Reply