copy folder structure from server

I need an script which copies the whole folder structure from a network volume which i want to choose manually to the desktop.

For example I have a volume called XSAN_live, which has 10 folders with all kinds of files in it. I want the app to let me manually point to this volume and then makes a new folder on the desktop called XSAN_live with the 10 folders in it but without all the files…

So i managed to find some snippets and put them together but the thing is it doesn’t copy subfolders in folders…

any idea’s someone ???


    set sourceFolder to choose from list (list disks)

    set sourceFolderName to (sourceFolder as text)

    set destinationFolder to ((path to desktop as text) & (sourceFolder as text))

    set folderList to {}

    tell application "Finder"
       set folderList to every folder of folder sourceFolder as alias list
    end tell

    if folderList is not {} then
       do shell script "mkdir -p " & quoted form of POSIX path of destinationFolder
       
       set pathLength to ((length of POSIX path of sourceFolder) + 1)
       repeat with oneFolder in folderList
           set restPath to text pathLength thru -1 of POSIX path of (oneFolder as Unicode text)
           do shell script "mkdir -p " & quoted form of POSIX path of destinationFolder & restPath with administrator privileges
       end repeat
    end if

Hi,

try this, you can add more filters in the /usr/bin/find line between the parentheses if there are other packages


set sourceFolder to (choose folder with prompt "choose source folder")
set sourceFolderName to name of (info for sourceFolder)
set destinationFolder to POSIX path of (choose folder with prompt "choose destination folder")
set folderList to paragraphs of (do shell script "/usr/bin/find " & quoted form of POSIX path of sourceFolder & " -type d \\( ! -path '*.app*' -and ! -path '*.rtfd*' -and ! -path '*.nib*' -and ! -path '*.mdimporter*' -and ! -path '*.xcode*' \\) ")
if folderList is not {} then
	set destinationFolder to destinationFolder & sourceFolderName & "/"
	do shell script "mkdir " & quoted form of destinationFolder
	set pathLength to ((length of POSIX path of sourceFolder) + 1)
	repeat with oneFolder in rest of folderList
		set restPath to text pathLength thru -1 of POSIX path of (oneFolder as Unicode text)
		do shell script "mkdir -p " & quoted form of (destinationFolder & restPath)
	end repeat
end if

Stefan,

as always thank you very much for your input. Your script works great on a regular folder but when I point it to the network volume I get al kinds of errors.

In the meantime I got the script almost to do what I want.

set sourceFolder to choose from list (list disks)

set sourceFolderName to (sourceFolder as text)

set destinationFolder to ((path to desktop as text) & (sourceFolder as text))

set folderList to {}

tell application "Finder"
	set folderList to every folder of entire contents of folder sourceFolder as alias list
end tell

if folderList is not {} then
	do shell script "mkdir -p " & quoted form of POSIX path of destinationFolder
	
	set pathLength to ((length of POSIX path of sourceFolder) + 2)
	repeat with oneFolder in folderList
		set restPath to quoted form of POSIX path of (oneFolder as Unicode text)
		set restPath to text pathLength thru -1 of restPath as Unicode text
		set eindres to POSIX path of destinationFolder & restPath
		do shell script "mkdir -p " & (quoted form of POSIX path of (eindres)) with administrator privileges
	end repeat
end if

The only thing that a folder called ’ (= apatroph or signle quotation mark) in every subfolder. I am sure it has to do something with the quoted form/posix path but I can’t seem the find the wrong one.

If you could help me further on this one…

kind regards,

Kemalski

Here is a Ruby example.

what kind of errors? The Finder method is quite slow so I’d prefer always the shell version.
But Craig’s ruby solution is probably the best one