Problem with file management.scriptd and moveItemAt

I am probably doing something silly, but in trying to use the example provided with ASObjC Explorer, I’m hitting a problem

I with to use the moveItemAt:POSIXPath toInsideFolder:folderPath handler included in the Mavericks example. If I hand it a file with not spaces in the path name, it works great.

set currentFullPathAndName to "/Users/me/Documents/file.pdf"
(theLib's moveItemAt:currentFullPathAndName toInsideFolder:"/Users/ghoetker/Desktop/")

However, if there is a space, as the below, it crashes. What should I be doing to avoid this? I am a novice here and would really appreciate any help.

set currentFullPathAndName to "/Users/me/Documents/file with space.pdf"
(theLib's moveItemAt:currentFullPathAndName toInsideFolder:"/Users/ghoetker/Desktop/")

Thank you.

A space in the file name shouldn’t make any difference. I notice your paths involve moving from one user’s folder to another user’s desktop – I wonder if you’re running into a permissions problem.

Thanks for the quick answer. I was trying to remove a lot of the extraneous material around the file names and screwed it up. In fact, everything is from within my home directory.

set currentFullPathAndName to "/Users/ghoetker/Documents/GPH_Endnote_2012.enlp/GPH_Endnote_2012.Data/PDF/3516616712/trust.pdf"
	(theLib's moveItemAt:currentFullPathAndName toInsideFolder:"/Users/ghoetker/Desktop/")

works, while

"/Users/ghoetker/Documents/GPH_Endnote_2012.enlp/GPH_Endnote_2012.Data/PDF/3516616712/trust with space.pdf"
(theLib's moveItemAt:currentFullPathAndName toInsideFolder:"/Users/ghoetker/Desktop/")

does not. The only difference is the name of the PDF.

With that eliminated, any other leads?

Thank you!

Change the handler to be like this:

on moveItemAt:POSIXPath toInsideFolder:folderPath -- moves file or folder; returns false if you try to overwrite
	set POSIXPathNSString to current application's NSString's stringWithString:POSIXPath
	set folderPathNSString to current application's NSString's stringWithString:folderPath
	-- build path for new file
	set theName to POSIXPathNSString's lastPathComponent()
	set newPath to folderPathNSString's stringByAppendingPathComponent:theName
	set theNSFileManager to current application's NSFileManager's defaultManager()
	set {theResult, theNSError} to theNSFileManager's moveItemAtPath:POSIXPathNSString toPath:newPath |error|:(reference)
	if theResult = false then
		error (theNSError's localizedDescription() as text) number -10000
	end if
	return (theResult as integer = 1)
end moveItemAt:toInsideFolder:

Now when it fails you will get an error telling you why. Let me know what it says.