Fileitem lasterrorcode problem

I try to move a file to trash. it is a bash file, extension .sh, sometimes it works sometime it does not.
no problems moving files to trash with other file extensions.
the weird problem is that the debugger shows the last error code of zero,
but in the script, I do a select case and the last error code is not zero,

would have liked to add a OS X screen shot ( name.png) to the message but don’t know how.

What are the permissions on the file, and where is it located?
How are you moving it to the trash? Are you using MoveFileTo or are you using the proper NSWorkspace declare?

the permissions are ok, the file is in my temp directory.
I use MoveFileTo, don’t know how to do it with NSWorkspace declare.
after I create that file, I set file permission to executable so the file can be run in a terminal.
as I mentioned, moving the file to trash using MoveFileTo sometimes work.
But the strange thing is the return code of the MoveFileTo function, the debugger shows zero and stepping through the code says 100, not found.

sorry, the return code says invalid name

any other file than .sh is working moving to trash.

probably it does not work because the file is a executable.

I removed the executable flag of the file permission, same as before, not working.

at the moment is works again, don’t know why, I leave it as it is, we will see

Is Terminal closed when you attempt this move? If it’s not closed, the OS may think Terminal is still using the file.

yes it is always open for testing, I keep an eye on it, thanks Tim