Link to home
Start Free TrialLog in
Avatar of Jon Allen
Jon Allen

asked on

Duplicate a file/folder structure in name only, from a single placeholder file duplicated and renamed.

Mac OSX question

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.

To reiterate, 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. Also, there are non-alphanumeric characters and spaces in the filenames to be duplicated.
Avatar of ArneLovius
ArneLovius
Flag of United Kingdom of Great Britain and Northern Ireland image

What are you trying to acheive with the "placeholder" files ?

As the "placeholder" files will have a different path to the actual files, when you reconnect your "offline" storage Plex will need to reindex again...

I would suggest instead keeping all of your media "online", and use rsync (or other application) to "mirror" your media to secondary storage.
Avatar of Jon Allen
Jon Allen

ASKER

https://www.experts-exchange.com/questions/29107027/Duplicate-a-file-folder-structure-in-name-only-from-a-single-placeholder-file-duplicated-and-renamed.html?anchorAnswerId=42617767#a42617767

What you are offering is an alternate strategy. I am looking for solutions for this specific question only. Someone with script skills should be able to come up with a solution for this specific question.
rsync can be used to copy a directory structure, but to create the "placeholder" files that you are after would be possible a "little" more complex than you expect.
$ Handle_Placeholder.sh -s "./SRC SRC" -d ./DEST
/bin/cp -ip ./SRC SRC/ placeholder 721p.mkv ./DEST/ placeholder 721p.mkv
/bin/cp -ip ./SRC SRC/asd"asd ./DEST/asd"asd
/bin/cp -ip ./SRC SRC/placeholder 721p.mkv ./DEST/placeholder 721p.mkv
/bin/cp -ip ./SRC SRC/placeholder720p.mkv ./DEST/placeholder720p.mkv
/bin/cp -ip ./SRC SRC/placeholder723p.mkv ./DEST/placeholder723p.mkv
/bin/cp -ip ./SRC SRC/`qwe qew  ./DEST/`qwe qew

Open in new window


$ Handle_Placeholder.sh -s "./SRC SRC" -d ./DEST
Need your comment when exception happens ? for ./SRC SRC/ placeholder 721p.mkv
Need your comment when exception happens ? for ./SRC SRC/asd"asd
Need your comment when exception happens ? for ./SRC SRC/placeholder 721p.mkv
Need your comment when exception happens ? for ./SRC SRC/placeholder720p.mkv
Need your comment when exception happens ? for ./SRC SRC/placeholder723p.mkv
Need your comment when exception happens ? for ./SRC SRC/`qwe qew

Open in new window

At windows you can use cygwin fi executeHandle_Placeholder.sh
$ /bin/cat Handle_Placeholder.sh
#!/bin/ksh
unset -f Usage
Usage ()
{
	if [ "SOURCE_DEST" = "$1" ]
	then
		echo "Usage to copy placeholder files:"
		echo "$0 -s SOURCE_DIR -d Different_DEST_DIR"
		echo "OR:"
		echo "$0 -s Different_SOURCE_DIR -d DEST_DIR"
		exit 1
	fi
	exit 1
}
if [ 4 -ne $# ]
then
	Usage $@
else
	while getopts "s:d:" arg
	do
		case $arg in
			s)
				if [ "${OPTARG}" = "" ]
				then
					echo "1 /bin/ls -ld $PWD/${OPTARG}"
					/bin/ls -ld "$PWD/${OPTARG}"
					Usage $@
				fi
				if [ ! -d "${OPTARG}" ]
				then
					echo "2 /bin/ls -ld $PWD/${OPTARG}"
					/bin/ls -ld "$PWD/${OPTARG}"
					Usage $@
				fi
				SOURCE_DIR=${OPTARG}
				;;
			d)
				DEST_DIR=${OPTARG}
				;;
			*)
				echo arg $arg
				echo OPTARG $OPTARG
				echo {OPTARG} ${OPTARG}
				echo 3 Usage $@
				Usage $@
				;;
		esac
	done
	if [ "$DEST_DIR" = "$SOURCE_DIR" ]
	then
		Usage SOURCE_DEST $@
	fi
	export LOGNAME=$(echo -ne "r\nq\n" | /usr/bin/gdb -q /usr/bin/whoami 2>&1 | /bin/grep -E -v "^\[|^\(|^Reading symbols from")
	if [ "" = "$SOURCE_DIR" ]
	then
		Usage $@
	elif [ ! -d "$SOURCE_DIR" ]
	then
		echo "3 /bin/ls -ld $PWD/$SOURCE_DIR"
		/bin/ls -ld "$PWD/$SOURCE_DIR"
	elif [ "" = "$DEST_DIR" ]
	then
		Usage $@
	elif [ ! -d "$DEST_DIR" ]
	then
		echo "4 /bin/ls -ld $PWD/$DEST_DIR"
		/bin/ls -ld "$PWD/$DEST_DIR"
	else
		SOURCE_LOCATION=$(/bin/basename "$SOURCE_DIR")
		DEST_LOCATION=$(/bin/basename "$DEST_DIR" | /usr/bin/tr -d "\n")
		for AllFiles in $(/usr/bin/find "$SOURCE_DIR" -maxdepth 1 -type f | /bin/sed "s/ /SPACE/g;s/\`/BACK_TICK/g;s/\"/DOUBLE_QUOTE/g;")
		do
			CURRENT_FILE=$(echo "$AllFiles" |\
			/bin/sed "s/SPACE/ /g;s/DOUBLE_QUOTE/\"/g;s/BACK_TICK/\`/g;")
			DEST_FILE=$(echo "$CURRENT_FILE" |\
			/bin/sed "s/$SOURCE_LOCATION/$DEST_LOCATION/;")
			if [ ! -f "$DEST_FILE" ]
			then
				echo /bin/cp -ip "$CURRENT_FILE" "$DEST_FILE"
				/bin/cp -ip "$CURRENT_FILE" "$DEST_FILE"
			else
				echo "Need your comment when exception happens ? for $CURRENT_FILE"
			fi
		done
	fi
fi

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.