Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Create symbolic links from multiple sets of source folders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create symbolic links from multiple sets of source folders
Authored by: CarlRJ on May 05, '10 04:13:34PM
Not to pick on AppleScript, but a scripting language like Perl (or Python, or Ruby, or...) can bypass a lot of the quoting gymnastics by talking directly to the kernel for things like symlink creation, rather than passing commands through the shell. This version is a bit more robust (it'll complain on errors, create symlinks to both files and folders found in the folders listed in sourceList, and as mentioned, obviates the need for escaping characters; it'll also tell what it's doing, if you remove the "#" before "print" towards the end); otherwise it's much the same, but in Perl...

use strict;
use warnings;

my @sourceList = (
    "/Volumes/Disk X/TV Shows",
    "/Volumes/Disk Y/Television shows",
    "/Users/Dave/Media/TV Shows",
    "/Volumes/Disk Z/video/tvshows"
my $destinationFolder = "/Users/Dave/Desktop/TV Shows";

foreach my $currentSource (@sourceList) {

    opendir SDIR, $currentSource  or do {
	warn "$0: can't opendir $currentSource: $!\n";
    my @sourceFolders = grep { not /^\.{1,2}$/ } readdir SDIR;
    closedir SDIR;

    foreach my $currentFolder (sort @sourceFolders) {

	my $fromPath = $currentSource     . '/' . $currentFolder;
	my $toPath   = $destinationFolder . '/' . $currentFolder;

	if (not -e $toPath) {
	    # print "Creating $toPath as symlink to $fromPath\n";
	    symlink $fromPath, $toPath
		or warn "$0: can't symlink $toPath to $fromPath: $!\n";
Edited on May 05, '10 04:15:15PM by CarlRJ

[ Reply to This | # ]