Remove the trailing slash from a folder
My company has several remote sites that rely on documentation I write here at WHQ in order to deploy macs according to company standards. Since these documents are in constant update mode, I wrote a small droplet that I use to just drop the documentation folder on and copy it to the remote site servers overwriting any existing documentation folder.
I have the following piece of code:
if CHIError is not equal to "" then
display alert CHIError giving up after 5
else
repeat with anItem in droppedItems
if ((kind of (info for anItem)) = "Folder") then
set anItem to quoted form of POSIX path of anItem
do shell script "cp -rf " & anItem & space & "/Volumes/MacPackaging$/MacDocumentation/"
else
set anItem to quoted form of POSIX path of anItem
do shell script "cp -f " & anItem & space & "/Volumes/MacPackaging$/MacDocumentation/"
end if
end repeat
end if
The problem I am running into is that when anItem is a folder and converted to a POSIX path, it ends up with a trailing slash, causing cp -r to copy only the contents of the folder and not the folder itself... Is there a way to remove the trailing slash or another conversion method I can use to copy the entire folder?
If I take out the if statement to check for a folder and the -r flag on cp, cp errors out telling me that anItem is a directory and can't be copied, which is to be expected. Ah... how I wish bash could do droplets...