Keep directory structure in Copy Files Build Phase in XCode

1k views Asked by At

In XCode 11.7, when I add a Copy Files build phase, it only allows me to select files, not directories, and while I can select files from within sub-directories, they all get mashed together into the top-level.

I can work around it by adding multiple Copy Files phases with a different subpath so that the structure ends up correct, but this is tedious and feels wrong.

Is there a better way to make the output directory structure of Copy Files match the input?

1

There are 1 answers

2
Nathan Friedly On

I figured out how to do it - instead of a Copy Files phase, I added a Run Script phase and used the cp -R command.

In my case, I wanted to copy a TargetApp/www folder to the "Wrapper" (root of the app), so my full script is:

echo "copying $SRCROOT/TargetApp/www to $TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH"
cp -R "$SRCROOT/TargetApp/www" "$TARGET_BUILD_DIR/$CONTENTS_FOLDER_PATH"