2 November 2014

Folders First!

I was recently asked whether it was possible to have ExpPrint list sub-folders before the file items in a folder. I had to admit that it wasn’t something I remember considering and so it wasn’t currently an option. However, with a bit of editing of the XSLT it is achievable.

The request was, that given a directory structure like this:

Folder1
files (in Folder1)
+SubFolder2
files (in SubFolder2)
+SubFolder3
files (in SubFolder3)





…which ExpPrint’s Detailed Table format currently lists that way. Instead, it should be listed folders first, like this:

Folder1
+SubFolder2
files (in SubFolder2)
+SubFolder3
files (in SubFolder3)
files (in Folder1)



As you may know from an earlier post on how ExpPrint works, the final output is created by an XSLT script that converts the intermediate XML form.


The part of the script that determine the listing order is in the file:



  • ProcessFilesAndDirs.xsl (for HTML detailed table)
  • ProcessFilesAndDirsCSV.xsl (for CSV detailed table)

Both are very similar with regards to the listing ordering, so I’ll only show the current ProcessFilesAndDirs file contents. You can find these files in your ExpPrint installation in the C:\Program Files\JD Design\ExpPrint\Plugins directory. Note these are the current version’s file contents, they may change subtly or radically in future versions.


You can edit XSLT files with a plain text editor such as Notepad, but for the sake of clarity I’ll show a collapsed view as displayed by the excellent free Notepad++.

SNAGHTML487793


The details are hidden by collapsing the source to illustrate the outline of what the code does.


The block between lines 25 and 88 process the file items, the folder “total”, and the optional blank spacer row.


The collapsed block between lines 89 and 110 perform the recursion into sub-folders.


You can probably guess now that all it takes to alter the listing so that sub-folders appear before items in the folder is to move the second block to be before the first one. i.e. like this:


SNAGHTML54403c


If you’d like to try this change, make a copy of the XSL file first – so that you have something you can return to.


Because the .xsl file resides in a protected area (under Program Files), you’ll need to run your text editor elevated (as Administrator), otherwise you won’t be able to save the file once you’ve modified it.


Here’s how the formats differ:










Default (files first)


Folders first

imageimage

If you prefer your listings this way, or maybe in some other form, please let me know and I’ll consider making changes to provide this layout easily.


I still prefer files first because it keeps the file items with the containing folder, whereas folders first doesn’t. For small listings like the above example this isn’t a great problem, but for long multi-page listings I’d find folders first difficult to understand.

No comments:

Post a comment