Applescript with a Do shell script dose not like spaces in file path.

When i try to do a shell script within an apple script, if there is a space in a name of a folder or file i know that the shell script will not like this if i put a \ before the space like in the termianl the applescript dose not like the \ in the file path. How do i get around this??

do shell script “ditto ~/Documents/my\ projects/ /backup\ server/backups”

Dunno if this works, but it compiles:

do shell script "ditto ~/Documents/my\\ projects/ /backup\\  server/backups"

another possibility is to add quotes (slashed for AS) instead of slashing the slashes:

do shell script "\"ditto ~/Documents/my projects/\" \"/backup  server/backups\""

:wink: Dominik

UNIX file names with spaces need to be quoted. The cleanest way to do what I think you’re trying to do is the following:

do shell script "ditto " & quoted form of "~/Documents/my projects/backup server/backups"

As already mentioned, a quote preceeded by a backslash ( " ) will also be passed a a quote to the Shell.

WF

Hi.

I’m not sure if I understand the problem correctly, so let me know if this helps:

do shell script "ditto ~/Documents/\"my projects\"/\"backup server\"/backups"

I hope it does

“Quoted form” would be the proper way to handle this:

get POSIX path of ((path to documents folder as Unicode text) & "my projects:")
do shell script "ditto " & quoted form of result & space & quoted form of "/backup server/backups"

“Quoted form of” tends to not work; I constantly get “file or folder not found” errors when using it even though the path is 100% correct. Removing “quoted form of” and using double backslashes fixes the problem (annoying as doing that is), so I recommend that method.

Is the quoted path being placed between single quotes in your script?