# Preserving Folder Tree Hierarchy using Export Plugins in 2.0



## ashepp

Hi Folks,  
 I've been trying to find a plugin that will allow me to select a top level folder and then export all images preserving the folders / subfolders. 

i.e. Select 2''8 and end up with export of all images in appropriate sub folders: 

2''8\beach shoot 
2''8\weekend shots 
2''8\wooded area 

Anyone know if this is possible on 2.' either natively or using a plugin ? 

Thanks 
Adam. 
[email protected]


----------



## Victoria Bampton

Hi Adam, welcome to the forum!

It's funny you should say that - we've been discussing the same thing this evening.  http://www.lightroomqueen.com/community/showthread.php?t=28'6

A plugin could be a very interesting workaround.  Tim Armes has written a couple, so he might be up for it, or Jeffrey Friedl has written a lot of plugins.  It'd be interested to know how many people would be interested in this kind of plugin, so add your requests below everyone!


----------



## Jim

Yes yes yes
This has been desperately needed for years.
I think Matthews templates come closest so far over at TTG.


----------



## johnbeardy

I'm pretty sure I did see someone announce a plugin that exports preserving the folder structure. It wasn't one of the usual suspects though, and I can't recall his name. Have a search around Adobe's forums (include the LR2 beta forum) for "exporting preserving the folder structure".

John


----------



## TerryM

I agree. Just trying to do the same thing. I have folder structure with 8 folders, each with 4 sub folders. Would like to export all raw files as jpgs and keep the same folder structure. The only way I see to do this now is recreate folders at destination, then export each folders contents to jpg, one at a time, until all 32 folders are done. Not a very good solution.


----------



## Mark Sirota

If you were on a Mac, you could export all to one folder using a filename template that included the directory names, then use a Folder Action to automatically move the files into appropriate subdirectories.

I bet there's some similar thing you can do on Windows, but I don't know what it is.


----------



## exi

I played around a bit with the SDK came up with this:
http://xipic.net/directoryexportfilter.lrdevplugin.zip

This plugin is a post export handler which will try to move the file into the directory structure after it has been exported.
It will try to create the whole needed underlying directory.

*This is how it works:*
At Export startup it will fetch the first picture of the catalog and compare it with the file path of the catalog to get the common basedir.
For example:

First picture is stored at 'D:\Eigene Dateien\Bilder\2''8\2''8-'8-23', your catalog is stored at 'D:\Eigene Dateien\Bilder\Kataloge\Alles'.
The common basedir is 'D:\Eigene Dateien\Bilder'.
This value is now preentered into the plugin configuration window.
Upon export the stringlen of that edit field will be taken off the physical path of the currently exporting photo and added to the export directory.

*Example: *exporting 'D:\Eigene Dateien\Bilder\2''8\2''8-'1-14\test\test2\IMG_8849.JPG' to 'C:\temp\test\' will result in '\2''8\2''8-'1-14\test\test2\IMG_8849.JPG' as addendum to the export directory so the final path is 'C:\temp\test\2''8\2''8-'1-14\test\test2\IMG_8849.jpg'
*
Why that complicated?*
Well, it isnt that complicated when you store your catalogs near the pictures as the plugin does the work for you.
However this was neccessary because i could'nt find a way to get the basepath out of Lightroom itself.

*What should i do when i store my catalogs far awar from the pictures?*
Either enter the path or just count the bytes and add a dummy text, only the string length is important.
Just remember that this is substracted from the physical storage of every picture and then readded to the export target directory.

*Known issues:* Lightroom will complain if the target file is already in the directory as it will create it there again.

This perfectly fits my needs, i hope this also helps on your situation.


----------



## Victoria Bampton

Very neat idea exi, welcome to the forum!

I'll have a play when I have time.


----------



## TerryM

exi said:


> I played around a bit with the SDK came up with this:
> http://xipic.net/directoryexportfilter.lrdevplugin.zip
> 
> This plugin is a post export handler which will try to move the file into the directory structure after it has been exported.
> It will try to create the whole needed underlying directory.
> 
> *This is how it works:*
> At Export startup it will fetch the first picture of the catalog and compare it with the file path of the catalog to get the common basedir.
> For example:
> 
> First picture is stored at 'D:\Eigene Dateien\Bilder\2''8\2''8-'8-23', your catalog is stored at 'D:\Eigene Dateien\Bilder\Kataloge\Alles'.
> The common basedir is 'D:\Eigene Dateien\Bilder'.
> This value is now preentered into the plugin configuration window.
> Upon export the stringlen of that edit field will be taken off the physical path of the currently exporting photo and added to the export directory.
> 
> *Example: *exporting 'D:\Eigene Dateien\Bilder\2''8\2''8-'1-14\test\test2\IMG_8849.JPG' to 'C:\temp\test\' will result in '\2''8\2''8-'1-14\test\test2\IMG_8849.JPG' as addendum to the export directory so the final path is 'C:\temp\test\2''8\2''8-'1-14\test\test2\IMG_8849.jpg'
> 
> *Why that complicated?*
> Well, it isnt that complicated when you store your catalogs near the pictures as the plugin does the work for you.
> However this was neccessary because i could'nt find a way to get the basepath out of Lightroom itself.
> 
> *What should i do when i store my catalogs far awar from the pictures?*
> Either enter the path or just count the bytes and add a dummy text, only the string length is important.
> Just remember that this is substracted from the physical storage of every picture and then readded to the export target directory.
> 
> *Known issues:* Lightroom will complain if the target file is already in the directory as it will create it there again.
> 
> This perfectly fits my needs, i hope this also helps on your situation.


 
exi, thanks. I did download and it works perfect for what I envisioned. I tried it several times on different files and it works great. Good job.


----------



## Sean McCormack

Exi,
If you do a proper page, I'll post it on Lightroom-news..
Sean


----------



## silviang

*Getting an error message while trying out the plugin*

Hello,
I have tried out this plugin but at the time of Export I get the following error message:


**** Error 1

The plug-in had an internal error while opening the Export dialog.
DirectoryExport.lua:1'': bad argument #2 to 'find' (string expected, got nil)
​From the error message I am not able to tell what is going on wrong. Has anybody got around the same thing?

Thank you.


----------



## TerryM

I works find for me running on a pc. Exports images and folder structure perfectly.


----------



## silviang

I have debugged the script today and it looks like there is an assumption embedded in the script - that the catalog file "lives" at the top level of the photo collection. In my case this is not how I setup the files (my catalog file lives on a different disk from where the photos are located). Under those circumstances the script will generate the error message that I reported.

One potential fix would be to find a way to identify the top level directory of the photo library. I am not sure yet whether there is a native function for such a thing.

Thank you,
Silvian


----------



## Sidor

I'm very interested in this plugin, but I'm getting the following error when trying to insert it from the Post-Process Actions: "The plug-in had an internal error while opening the Export dialog."

I might have a fix to the problem silviang describes, but can't test it when I can't use the plug in.


----------



## silviang

Are you getting this error message on the original version or after you did some changes? What version of LR are you using - maybe there is a function usage problem that is supported in LR2.' only. 

One thing you can do is to attach the Windows Debugger before you hit the "Export" button - you might get additional messages


----------



## Sidor

I'm getting the error in your original plugin (without modifications), and I'm using LR 2.'.

Could you elaborate on how I attaches the Windows Debugger?


----------



## silviang

This is actually not my original plugin - I have downloaded it from this thread and I was lucky to see that the code is not binary so I was able to debug this.

With respect to how to attach WinDebug to this. I learned this from the LightRoom SDK documentation present here: 
http://www.adobe.com/devnet/photoshoplightroom/

Open the Lightroom SDK Guide.pdf and go to page 166 - it explains all the steps to follow.

Thank you,
Silvian


----------



## Sidor

Oh well, I ment "the original plugin" and not yours. I was in a hurry when posting.

I've tried attaching the debugger and the only things I got was:



> L: libraryLogger    TRACE    E:\Lightroom
> L: libraryLogger    TRACE    F:\Pictures\2''8\2''8.'8.31
> (323'.3234): C++ EH exception - code e'6d7363 (first chance)


----------



## silviang

I think that I recognize it. Yes you have the same problem as me. What is going on in the code is that the "basesearch" variable is "nil" since the location of LightRoom catalog is very different than the location of the picture. Try the following change and let me know if you see a change:

Replace the "while securityCount > '" loop from DirectoryExport.lua with:



		Code:
	

while securityCount > ' do
        if (string.find(firstPhotoPath, basesearch)) then
            break
        end
        basesearch = LrPathUtils.parent(basesearch)

[B]        if (basesearch == nil) then
            DirectoryExport.toLog("basesearch is nil at this point")
            basesearch = 'F:\\Pictures'
            break
        end[/B]

        DirectoryExport.toLog("basesearch: " .. basesearch)
        securityCount = securityCount + 1
    end

If that does not work, add some more:



		Code:
	

DirectoryExport.toLog("Debug point: " .. basesearch)

to see where it breaks.

Thank you,
Silvian


----------



## Sidor

Thanks silviang -your fix worked. I just didn't realize that the code with the problem were being access at that point in the process.

I've been looking through the API documentation and saw that there was a wa to filter photos that should not be included in the rendition process. I thought I could use this for skipping photos that had been processed previously, but unfortunately the function for removing photos don't have access to the destination path, so I can't check if the photos already exist. Of course the path could be hard coded, but if that's the only solution, I won't bother.


----------



## exi

silviang;2228' said:
			
		

> This is actually not my original plugin - I have downloaded it from this thread and I was lucky to see that the code is not binary so I was able to debug this.



I saw no point in compiling those few lines, i'm a friend of open source.

I didnt knew that basesearch could become nil, however i tried to make the script so it can be used on your case (hence the security count, its an emergency loop exit in case no common basepath can be found - which is the case if you dont store your catalog on the same disc as the pictures).

I'll include your fix in a possible next version however my system crashed (windows registry :/) and i need to reinstall windows to be able to use lightroom again (nasty vc++ runtime exception error) but this takes some time.


----------



## mixx

*I need to come back to this question*

Can any kind soul help me, please?

I started to use the original version of this plugin and it is my most used plugin of all.

All of a sudden, it stopped working and I am getting the "The plug-in had an internal error while opening the Export dialog."
error. 

I have not changed anything on my system except that I upgraded to LR 2.2 (but would swear it worked after that).

My LR related stuff lives in E:/Lightroom, my pictures are in E:/Photos and the destination of export is in E:/Output/XVGA.

This setup worked by specifying "E:" as the common root.

It does not work anymore and the fix above does not help either.

Since I used to generate all my output with this plugin, I am quite desperate. Can anyone please help me? Has anyone been successful in running this plugin under LR 2.2?

Unfortunately, I can not run windbg with LR together, LR freezes if I attach it to the debugger.

When the plugin is installed, it seem to OK and activated. When I call the Export menu (*before* attempting an export), there is already a message at the bottom of the panel: "The plug-in had an internal error while opening the export dialog". This sounds to me, as if there was a problem aside from the basename issue.

Thanxx, Peter


----------



## TerryM

mixx said:


> Can any kind soul help me, please?
> 
> I started to use the original version of this plugin and it is my most used plugin of all.
> 
> All of a sudden, it stopped working and I am getting the "The plug-in had an internal error while opening the Export dialog."
> error.
> 
> I have not changed anything on my system except that I upgraded to LR 2.2 (but would swear it worked after that).
> 
> My LR related stuff lives in E:/Lightroom, my pictures are in E:/Photos and the destination of export is in E:/Output/XVGA.
> 
> This setup worked by specifying "E:" as the common root.
> 
> It does not work anymore and the fix above does not help either.
> 
> Since I used to generate all my output with this plugin, I am quite desperate. Can anyone please help me? Has anyone been successful in running this plugin under LR 2.2?
> 
> Unfortunately, I can not run windbg with LR together, LR freezes if I attach it to the debugger.
> 
> When the plugin is installed, it seem to OK and activated. When I call the Export menu (*before* attempting an export), there is already a message at the bottom of the panel: "The plug-in had an internal error while opening the export dialog". This sounds to me, as if there was a problem aside from the basename issue.
> 
> Thanxx, Peter



 I am getting the same error since upgrading to LR 2.2 I just tried to send a email to the developer to see if he may have a solution.


----------



## Eric_V

Now I too was having some trouble with this plug in, and really needed this feature. So i spent an hour or so playing with it, and think i have a "fix".

The problem seems be the way lightroom executes catalog:findPhotos.  Certain functions that can take a long time to execute need to be run a little diferently.  This script was not running catalog:findPhotos correctly.

Now this is my first experience with this scripting language and lightroom, so this "fix" really is a hack.  I know there is a more correct way to do this, but I really do not have the time to really get into this and clean it up properly.  There are also a number of functions that are depreciated being used by this plug in.  This will need to be addressed as well before the functions are no longer supported.


OK, enough with the explanation, here is how I got the plug in working

In DirectoryExport.lua

right below the line:


		Code:
	

	function DirectoryExport.getCommonBasedir()

Add:


		Code:
	

	import "LrTasks".startAsyncTask( function()

then in that same function right below the lines:


		Code:
	

	DirectoryExport.toLog("common basedir: " .. basesearch)
	return basesearch

add:


		Code:
	

	end)

Eric


----------



## mixx

Eric,

I tried the changes and they do not work for me (I am on Vista and LR 2.2), I still get the "plugin encountered internal problem message.

Just in case I am too stupid to follow your instructions, would you mind to post the whole file (so that I can just cut&paste)?

Slim chance, I know (and I am desperate, I need this plug-in).

Thanks for doing this,

Mixx


----------



## ashepp

Hi Folks,  
 I've been trying to find a plugin that will allow me to select a top level folder and then export all images preserving the folders / subfolders. 

i.e. Select 2''8 and end up with export of all images in appropriate sub folders: 

2''8\beach shoot 
2''8\weekend shots 
2''8\wooded area 

Anyone know if this is possible on 2.' either natively or using a plugin ? 

Thanks 
Adam. 
[email protected]


----------



## Eric_V

I did my testing on lightroom 2.2 running on vista 64, and it worked for me.

Since I am not able to attach the plug in directly, you can download the modified plug in from here http://www.voskanian.net/files/directoryexportfilter.zip

It would be nice to find a more permanent home for this, or even better someone to maintain it.  For now I can host it.


----------



## mixx

Eric,

thanks a million. That did it. I confirm, that the above code works now for me running on Vista-32 with LR 2.2.

Thank you *so* much,

Mixx


----------



## TerryM

Eric_V said:


> I did my testing on lightroom 2.2 running on vista 64, and it worked for me.
> 
> Since I am not able to attach the plug in directly, you can download the modified plug in from here http://www.voskanian.net/files/directoryexportfilter.zip
> 
> It would be nice to find a more permanent home for this, or even better someone to maintain it.  For now I can host it.



Eric, I tried your modification, Win XP, SP2 running LR2.2 and it now works. Thanks for the effort. Greatly appreciated.


----------



## johnbeardy

Well done Eric - I'd looked at LrTasks but couldn't see the solution. 

I just tested it on Mac Leopard and it works sufficiently well. I did notice that beneath the "Target Folder" on my desktop, the folder path is a bit longer than needed - TargetFolder/ers/john/pictures/2''9/YYMMDD/. I don't know where the ers has come from. But it works fine.

John


----------



## exi

Thanks for the hint Eric.

Today i implemented it with a bit less dirty hacking and also reworked the path display to what i originally had in mind.

See for yourself:





It automatically fills the comobox with values down of the path of the first picture in the collection up to the common basedir. That value is selected and then one additional parent directory is added if possible, i hope this satisfies most people.

get the updated version here:http://xipic.net/directoryexportfilter.lrdevplugin2.2.zip


----------



## mixx

Hi exi,

thank you for your effort! A bit of feedback: the resulting folder structure drop-down menu and the line below it indicating what I'll have now does not get updated on my setup. Thus it does not reflect what I am trying to achieve right now, it has a path stored from some past operation (the path does exist and I used it in the past) but not the current one.

I find this quite a bit confusing.

I am on Vista32 with LR 2.2

Thanks, Mixx


----------



## R_C_

Thank you exi.
Was hoping for a way to do this, and you have provided it.

Regards,
Richard.





			
				exi;344'6 said:
			
		

> Thanks for the hint Eric.
> 
> Today i implemented it with a bit less dirty hacking and also reworked the path display to what i originally had in mind.
> 
> See for yourself:
> 
> 
> 
> 
> 
> It automatically fills the comobox with values down of the path of the first picture in the collection up to the common basedir. That value is selected and then one additional parent directory is added if possible, i hope this satisfies most people.
> 
> get the updated version here:http://xipic.net/directoryexportfilter.lrdevplugin2.2.zip


----------



## ensnare

I have an alternative way to do this for mac users:
First, set up the appropriate folder structure.  For me, it's

/Volumes/data/Library/Originals/2''9
/Volumes/data/Library/Modified/2''9

And I change the year each year.  The final year is optional, but just so you can see how mine is configured, I'm mirroring my setup.

Then, set your export profile to export to the root directory of
/Volumes/data/Library/Modified/2''9

Set the filename to:
*(Folder Name)Filename* in the custom settings. No spaces.
My script uses the ()'s as delimiters to export the folder title information within the file.

Then, create this little script and tell lightroom to point to it under Post-Processing

#!/bin/bash
path='/Volumes/data/Library/Modified/2''9'

FILES=`ls -lah $path | grep "(2''9" | awk -F ")" {'print $2'}`

for file in $FILES
do
        folder=`ls -lah $path | grep "(2''9" | head -1 | awk -F "(" {'print $2'} | awk -F ")" {'print $1'}`
        file=`ls -lah $path | grep "(2''9" | head -1 | awk -F ")" {'print $2'}`
        full_file=`ls -lah $path | grep "(" | head -1 | awk -F "(" {'print $2$3'}`
        mkdir -p "$path/$folder"
        mv -f "$path/($full_file" "$path/$folder/"
        mv -f "$path/$folder/($full_file" "$path/$folder/$file"
done

To create the script:
vim move.sh
i
copy and paste the script
:wq
then change the permissions
chmod a+x move.sh

And you should be good.  The script will automatically read the foldername between the ()s and create a folder with that title, move the file into that folder, and remove the () portion.  It works pretty well from my experience, doesn't require any plugins, and is very fast.

Good luck !


----------



## mixx

Folks,

I need help (just a little) with this plug-in. I use it very often to generate a lower resolution export copy of my tree for display on a LCD-TV or digital picture frame.

Lightroom is very handy, I defined a smart collection "Changed in last Month" that lists me all the images I changed in any way in the last month. Now I could export only those.

But here is the rub. The plug-in seems to check if there is an existing copy of the images *on the top level* level of the hierarchy and prompt what to do. But *after that*, when the images is moved to its place in the hierarchy, it does not seem to check again, if there is a file by that name there. If there is, I get the message "Could not move file to destination" and I am not given the option to overwrite it. Thus it is impossible to re-export existing images.

I'd much rather overwrite existing files. How do I change the code for that? It must be just a little tweak.

Can anyone please help?

Thanxx, Mixx


----------



## mixx

OK, I seem to have solved the problem by myself (even though I have zero knowledge how these plug-ins work). But I did find a plug-in by Jeffrey Friedl and following that I changed the code in DirectoryExport.lua (at the bottom) of the function DirectoryExport.postProcessRenderedPhotos from


		Code:
	

local newDestinationPath = LrPathUtils.child(folder, newFile)
local status = LrFileUtils.move(sourceRendition.destinationPath, newDestinationPath)

to this



		Code:
	

local newDestinationPath = LrPathUtils.child(folder, newFile)
   -- I'm not sure what happens with the move/copy when the destination
   -- exists, so I'll try to delete it, just in case it's there
LrFileUtils.delete(newDestinationPath)
local status = LrFileUtils.move(sourceRendition.destinationPath, newDestinationPath)

an that seems to have solved the problem. Existing files are deleted first and the new copy is moved to that location only after that.

Cheers, Mixx


----------



## DarXtalker

Yeah, just to say to be careful with "(" in the rest of the filename, it'll crash the sript.

++


----------



## Kharisma

Hi! Ok, so I know this is a bit of an old topic now, but I just discovered this topic and the plugin in it the other day and have found it to be VERY helpful! (Thanks a million Exi et al!!)

However, I'm having one problem that I'm hoping someone can help me with. You can see the quote below for the latest version of this script. It takes a base directory as input, and then exports your exact directory structure starting from your base directory. My problem is that every time I open the export dialog, it has the mac root folder (/) selected as the directory- Apparently from reading the posts, there is a loop in the script that attempts to find the catalog folder and fill in this info for you, but for these projects I'm using a different drive than my catalog. The "dropdown box" that is also supposedly built into this scrip is also too wide for my version, so that's no help either.

Basically, what I'd like the script to do is stop trying to automatically figure out what folder it should pick, and just remember the last thing I typed into it every time I load it up. Even better would be if it would save the directory into the export preset I try to save the settings to.

I have a bit of programming exp, and I just downloaded the SDK today- but haven't been able to make much sense of it so far. Any help would be *greatly* appreciated!!

Thanks, 
Kelsey

MacBook Pro Intel, OS X 1'.5.8
Lightroom 2.4

[quote author=exi link=topic=281'.msg344'6#msg344'6 date=1232149536]
Thanks for the hint Eric.

Today i implemented it with a bit less dirty hacking and also reworked the path display to what i originally had in mind.

See for yourself:
[img width=6'' height=1'1]http://xipic.net/direxport.jpg[/img]

It automatically fills the comobox with values down of the path of the first picture in the collection up to the common basedir. That value is selected and then one additional parent directory is added if possible, i hope this satisfies most people.

get the updated version here:http://xipic.net/directoryexportfilter.lrdevplugin2.2.zip
[/quote]


----------



## Tim Armes

Very late reply - just seen this thread.

Try this, it does just what you ask:

http://www.photographers-toolbox.com/products/lr2treeexporter.php

Tim


----------



## areohbee

Try TreeSync3 - it not only exports into a tree, but includes change detection and purging of extraneous photos from the destination, - just like the new publish feature except accessed as an export.


----------



## mixx

Well, I actually switched to TreeSync3 and I am very satisfied with it. This change detection capability is real handy if you have a couple of thousand images.

Thanks, Rob, for sharing it with us for free.

Ciao, Mixx


[quote author=areohbee link=topic=281'.msg64167#msg64167 date=127'8853'8]
Try TreeSync3 - it not only exports into a tree, but includes change detection and purging of extraneous photos from the destination, - just like the new publish feature except accessed as an export.
[/quote]


----------



## areohbee

[quote author=mixx link=topic=281'.msg65614#msg65614 date=1272488'79]
Well, I actually switched to TreeSync3 and I am very satisfied with it. This change detection capability is real handy if you have a couple of thousand images.

Thanks, Rob, for sharing it with us for free.[/quote]
Glad its working for you Mixx, and thank you for expressing your appreciation. - Please let me know if you have any troubles with it.


----------



## mixx

Rob,

there is one thing you could consider changing:

even if I do not check the verbose box, the plug-in still lists all images informing me that they are unchanged. With 2',''' images, it is sort of a long list. An option (or just re-interpretation of 'non-verbose') would be nice, that would suppress "unchanged" messages.

Thanxx, Mixx


----------



## areohbee

[quote author=mixx link=topic=281'.msg66'52#msg66'52 date=1273'9'853]
Rob,

there is one thing you could consider changing:

even if I do not check the verbose box, the plug-in still lists all images informing me that they are unchanged. With 2',''' images, it is sort of a long list. An option (or just re-interpretation of 'non-verbose') would be nice, that would suppress "unchanged" messages.

Thanxx, Mixx
[/quote]Done.

See v3.8.2


----------



## mixx

Thanks a million, Rob. I particularly like the "honorary update" thing 

Thanxx, Mixx


----------



## areohbee

[quote author=mixx link=topic=281'.msg66'89#msg66'89 date=1273128931]
Thanks a million, Rob. I particularly like the "honorary update" thing 

Thanxx, Mixx
[/quote]
Its my pleasure to serve... ;~)
-R


----------



## mixx

Rob,

I just noticed that even though I specify the location of the log-file in the plug-in, this path is ignored and the file always ends up in my $HOME\Documents folder with the latest release (3.8.3).

I am using LR 2.5 on Vista Premium Home 32bit.

Cheers, Mixx


----------



## areohbee

Yeah, I'm not crazy about that "feature" either, but its what you get when you use the standard Lightroom logger. I used a home-brewed logger for the first few years which respected the path. I'll submit a feature request on the Lightroom SDK forum - thanks for the reminder.

Rob


----------

