Copying an entire folder structure with none of the enclosed files

Tim Lloyd's icon

^^ pretty much sums up what I'm trying to do.

I've been trying to do this by using Alex Harker's [recursivefolder] object to list all the sub-folders within a given folder, lopping off the folder names and then concatenating them on the end of a new path ...

This works, but only if the parent directory only contains a single sub-level (if that makes sense).

So if I had:

parent/
parent/child_1
parent/child_2/sub_child_1
parent/child_3

(where all the above are simply folders)

... I can't work out a way of automatically finding out how many sub-levels are within the main parent folder in order to be able to copy the whole structure correctly.

If anyone has any experience doing such a thing in max some tips would be great :)

///

Outside the realm of max, there seems to be a really simple way of doing it by using the OSX "ditto" command in conjunction with a bom file.

If there is a way of creating a bom file that includes only the folder structure without any other files at all that may be in any of the folders, then it's easy to do the copying from max via the [shell] object.

I could just generate a bom file of the parent folder, use it with the "ditto" command to copy the structure to a new path, and then delete the bom file.

However, I can't work out how to generate such a stripped-down bom. The following command generates a simplified one containing only file paths, but this includes files within folders ...

mkbom -s source_directory bom_filename

Does anyone have any experience with this?

Thanks :)

Zachary Seldess's icon

Hi Tim,

Try sending something like this to [shell]:

find -type d -print

best,
Zachary

Tim Lloyd's icon

Thanks, I know how to do that and it gives me the same results as [recursivefolder] - a list of all the folder paths, but this isn't the issue I'm having (unless I'm failing to infer something).

The issue is that when I strip the folder names from their paths (via strippath or regexp) in order to be able to append them each to a new path, I lose the ability to differentiate between folders at 1 level down and ones further down ... i.e.

Desktop/test/folder_1
Desktop/test/folder_1/level_1_1/level_2
Desktop/test/folder_1/level_1_2

becomes:
folder_1
level_1_1
level_2
level_1_2

... so then simply appending these onto a new path cannot rebuild the original structure correctly.

Maybe I'm thinking of this in the wrong way? Perhaps I should be asking if there is a way to split a path before a specific directory when interpreted "from left to right" ... i.e. in the above example, always split the path before "folder_1" which is the uppermost folder in the structure that I want to keep.

Then it would be possible to simply append all the results onto a new path to create it elsewhere.

I shall do some more searching ... it seems like such a simple thing to do ... if only ditto had a "folder only" option :)

Tim Lloyd's icon

... and I'm pretty sure that I just worked it out with Jasch's [strlen] and [strcut] :D

They should definitely be standard distro.

Zachary Seldess's icon

Glad you figured a way. I'd normally use regexp for something like this, but in this case OSC-route works beautifully. So here's another way...

best,
Zachary

Max Patch
Copy patch and select New From Clipboard in Max.

Tim Lloyd's icon

Yeah that's much more efficient than the way I'm doing it. However, my method is able to "ignore" empty folders (thanks to AH's [recursivefolder]) which is very useful in the patch. It needs a bit of tweaking, because it will only ignore a folder that doesn't contain another folder ... so if there were a lot of empty folders inside each other it would output paths for all except the lowest level ...

It works for what I need it for anyway though, and empty folders are not a particular concern - I'm using it for batch-conversion of audio files in nested folders, so I'm only interested in keeping folders with audio in them anyway.

But yes ... it seems like I can use the ideas in your patch to make mine better :)

Max Patch
Copy patch and select New From Clipboard in Max.

cheers,
Tim

Tim Lloyd's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's a version using [OSC-route] (thanks Zach!) and [recursivefolder] (thanks Alex!) which lists all the subdirectories in a chosen directory which are not empty so that the tree can be rebuilt elsewhere :)