Forums > MaxMSP

Copying an entire folder structure with none of the enclosed files

Aug 01 2011 | 3:31 pm

^^ 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:


(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 :)

Aug 01 2011 | 7:00 pm

Hi Tim,

Try sending something like this to [shell]:


-type d -print


Aug 01 2011 | 7:25 pm

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.



… 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 :)

Aug 01 2011 | 7:42 pm

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

They should definitely be standard distro.

Aug 02 2011 | 7:54 am

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…


— Pasted Max Patch, click to expand. —
Aug 02 2011 | 9:22 am

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 :)


-- Pasted Max Patch, click to expand. --

Aug 02 2011 | 2:36 pm

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 :)

-- Pasted Max Patch, click to expand. --

Viewing 7 posts - 1 through 7 (of 7 total)

Forums > MaxMSP