I have a large library of digital media. Most of it is kept "offline" but the library software I use (Plex) uses media files to build the library and so I need to use placeholder files.

Using 30 second "this file is archived" videos I can easily catalog offline movies in Plex. I "rsync" the directory structure without files and then "do cp" a placeholder into each movie directory and rename using the parent folder name.

For TV shows this isn't practical as there can be hundreds of episodes per show. I would like to know if there is a way to duplicate the folder/file structure of a tv show, with many episodes under a single folder, using the same placeholder file.

I think there is a way to create folders from the filenames, then copy the placeholder into each new folder, rename using the folder name and then move the files back out to a single directory, but I don't know how.

1 Answer 1


Here is what I would do (there may be more efficient ways to automate this, but this is a quick hack that should achieve what you need). I hope I've understood your question correctly.

To get a list of all the directories (and their subdirectories) within an existing directory:

Open Terminal, and navigate to the existing folder containing the structure you would like to duplicate (if you are not familiar with Terminal, I am happy to give more specific guidance on how to do this. Basically, if you think of Terminal like Finder, the default folder that you are "viewing" when you open Terminal is your user folder. From there, you can type pwd to see where you are, ls to see a list of everything in the current directory, cd [folder name] to move into a folder in the directory, and then cd .. to move back up a level to the parent directory).

Type the following command:

find . -type d

This will list all of the directories contained in the current directory, as well as each of their subdirectories (i.e. it will not stop searching until there are no more subdirectories to enter).

The list will have entries that look something like this:


We need to clean the formatting up just a bit before we can use this text.

To clean up the text so it can be used to recreate that folder structure:

Copy this list into any plain text editor (not Microsoft Word); I use TextWrangler but TextEdit comes with your computer. Using the find and replace feature, remove every instance of ./ (leave the "replace with" box empty and press replace all). This will delete all the initial periods and slashes, but retain subsequent slashes which indicate subdirectories.

Also, delete all new lines (i.e. the text may wrap onto multiple lines, but there should be no explicit new paragraphs in there). The above example will now look like:

directory1 directory1/subdirectory1 directory2 directory2/sub2/sub3/sub4

To create an arbitrary number of new folders with one command:

Note: You could also do this step using folder names from a different source, I was slightly confused by what the source of the folder names was in your question

You should now have a list of folder/subfolders that is all on one line (though it may wrap to multiple lines when it is rendered in your text editor), and has no punctuation*. Copy all of this text to your clipboard. Go back to Terminal, and use cd [folder], cd .., ls and pwd to navigate to the destination folder where you want to recreate the folder structure, as described above.

Once you are in the right folder, type:

mkdir -p and then commandv, and hit enter. Make sure there is a space (and nothing else) between mkdir -p and the first directory name, and one space between each subsequent directory name.

I know people have varying levels of familiarity with UNIX and the Terminal environment, so if this is confusing feel free to comment which steps need more clarification.

*Note that if any of the directory names you paste into Terminal have spaces or non alphanumeric characters such as (./'!?:_) etc., you need to escape them or it will not work. That is, for every space or other weird character, you must put a \ directly before it (note the difference between \ and /). So music/the beatles becomes music/the\ beatles. You can use find and replace for this as well.

  • Thanks for all that info! I should clarify that the ultimate goal is to take a placeholder file eg. "placeholder720p.mkv" and use this file to recreate the source directory with the same filenames. So in the end I will have a folder that looks identical to the source, but consists of this placeholder file duplicated over and over. Your idea would work well except for the many non-alphanumeric characters in the source files/folders. Is there another way to achieve this, maybe using automator or a script, that would not be hindered by the need to put a \ before each non-alphanumeric character?
    – Jon Allen
    Jun 23, 2018 at 3:55
  • @JonAllen I'm an idiot. There was a much simpler way to do this which takes like 2 lines and handles the special characters without issue. I'm about to update the answer. Jun 25, 2018 at 20:24
  • @JonAllen sorry, before I respond could you confirm (sorry I misunderstood before): You have been using rsync and a cp loop, which worked well for movies, as there is typically just one file per folder. However, the challenge with TV shows is that a single folder holds many files, and the filenames are not extractable from the folder names. So actually you are already able to recreate the folder structure--the issue is in copying the same placeholder file so that there are multiple (correctly-named) copies in each folder. Jun 25, 2018 at 20:35
  • And then let me also ask: Do you have any way to get your library data into some other format like a CSV or XML file, or is the file structure the only available representation of the data (by "data" I mean the names and respective shows/seasons of each episode in your collection) Jun 25, 2018 at 20:38
  • Hi Luke, thanks for your reply. Yes you understand the problem correctly. The plex app does keep everything in a database that can be extracted as a csv, but its not formatted the same way as the filenames. It would be several extra steps to extract and reformat this, repeat for each show to be archived. Much easier to use the file structure if thats possible.
    – Jon Allen
    Jun 26, 2018 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .