Yes, it's possible.
I thought about ways to do this, and I see two basic approaches:
1. Copy the entire original disk or folder to the destination, then go through and truncate every file to zero length.
2. Traverse the directory tree of the original disk or folder, and replicate every directory on the destination, then for each original file, create a zero-length file.
One problem with approach #1 is that it requires copying huge amounts of data, just to truncate it (toss it). Another problem is that things like color tags, creator codes, "Open with" assignments, etc. aren't as easy to remove or truncate as the data in the copied file. These can add up to a significant amount.
One problem with approach #2 is it won't preserve alias files, symlinks, hard-links, etc. without some extra fiddling around. For a reusable program, such fiddling might be a worthwhile investment for the developer. For a one-off program, not so much.
So here's the steps and the code.
I've given it as an Automator workflow containing two script actions: one AppleScript (for user interaction), then one shell script (for doing the work).
- Launch Automator.app, and create a new Workflow from the template-chooser that comes up.
- Drag a Run AppleScript action to the workflow sequence, then replace the entire prototype script with this:
Code:
try
choose folder with prompt "Choose the folder to make Phantom from."
return POSIX path of result
on error
return "-"
end try
- Drag a Run Shell Script action to the end of the workflow, and replace its entire prototype script with this:
Code:
echo "got: $1"
[ "$1" == "-" ] && echo "Stopped" && exit
[ ! -d "$1" ] && echo "Must be a directory: $1" && exit
OUT="$HOME/Desktop/Phantom"
mkdir -p "$OUT"
exit 0 ## early_stop
cd "$1"
find . -type d -exec mkdir -p "$OUT/"{} \;
find . -type f -exec touch "$OUT/"{} \;
- At the upper right of the Run Shell Script action's pane, locate the "Pass input:" popup and set it to "as arguments". It defaults to "to stdin".
- Save the workflow.
- Run it.
- It should ask you to choose a folder to make the phantom from. Do so. It should then make an empty folder named "Phantom" on your desktop. Confirm it does this. If it doesn't do this, post again, providing any error message from the Results view of the workflow.
- If the "Phantom" folder is created correctly, then find this line in the shell script:
and change it to this:
That is, insert a # character at the start of that line. This converts the line into a shell comment, which means it's not executed, which means that the commands coming after it WILL be executed.
- Save the workflow, then Run it again. Choose a folder. I suggest choosing a smallish folder with sub-folders and files, or at least not a huge folder with hundreds or thousands of files. We're still only doing testing at this point.
- When the workflow completes, the "Phantom" folder on your Desktop should now contain a replica of the original's folder structure, and every file should be zero bytes in length. If it doesn't do this, post again, providing any error message from the Results view of the workflow.
- At this point, you can trash the test-case "Phantom" folders on your Desktop, then run the workflow and choose the real disk or folder you want to phantomize.
If something in the above steps fails or doesn't work, post again.
If you want an explanation of anything in the scripts, ask again, with a specific question about a specific part of the script. I used some unconventional idioms for concise checking of the input parameter. The rest is pretty conventional shell scripting.
This workflow can also be enhanced. For example, it could allow you to name the output folder, place it somewhere other than Desktop, report any errors it finds during the scan, create a disk-image to write the phantom to directly, etc. All of those things take extra development work, which also means extra time for testing.