Move file to the trash
I can see that moving files to trash by using the following code:
CLEAR LOCAL LOCAL FN getDirID&(wdRef%) DIM pBlk.200 DIM 31 fldr$ pBlk.ioNamePtr& = @fldr$ pBlk.ioVRefNum = wdRef pBlk.ioFDirIndex = -1 osErr% = FN GETCATINFO(@pBlk) END FN = pBlk.ioDrDirID& ' 0 if not found CLEAR LOCAL LOCAL FN moveFileToTrash%(fName$,srcWD%,trashWD%) DIM pBlk.220 DIM osErr% pBlk.ioNamePtr& = @fName$ pBlk.ioVRefNum = -1 pBlk.ioDirID& = FN getDirID&(srcWD%) pBlk.ioNewDirID& = FN getDirID&(trashWD%) osErr% = FN CATMOVE(@pBlk) END FN = osErr% CLEAR LOCAL LOCAL FN GetSysFolderVol%(type&) DIM pBlock;128 LONG IF type& = _kTemporaryFolderType Create = _KCreateFolder XELSE Create = _kDontCreateFolder END IF LONG IF FN FINDFOLDER (_kOnSystemDisk,type&,Create,Drive%,DirID&) = _NoErr pBlk& = @pBlock pBlk&.ioVRefNum% = Drive% pBlk&.ioWDDirID& = DirID& IF FN OPENWD (pBlk&) = _noErr THEN Vref% = pBlk&.ioVRefNum% END IF END FN = Vref% CLEAR LOCAL LOCAL FN myMoveFileToTrash%(fNameToTrash$, theSrcWD%) DIM moveTrashErr%, theTrashWD% theTrashWD% = FN GetSysFolderVol%(_kTrashFolderType) LONG IF theTrashWD% moveTrashErr% = FN moveFileToTrash%(fNameToTrash$,theSrcWD%,theTrashWD%) LONG IF moveTrashErr% = _noErr 'file moved to trash ok... XELSE 'file moved to trash failed... 'instead do copy to trash then kill?????????? END IF XELSE moveTrashErr% = _true END IF END FN = moveTrashErr% err% = FN myMoveFileToTrash%(myFileName$, myWD%) LONG IF err% = _noErr 'file moved to trash ok... XELSE 'file moved to trash failed... END IFwill move files locally....
will it also work over a network on a remote volume, or, on a remote volume do I have to do a copy to trash folder and the a kill file in source folder?
I think it will _not_ work for files that are on any volume other than your startup volume. A CATMOVE cannot move files across volumes, and therefore can't put other volume's files into your startup volume's trash.
Nor do I think you want it to. It would be "bad HIG" to put Volume "A"'s files into Volume "B"'s trash. Most volumes have their _own_ trash folder (even floppies do), and that's the trash into which you should move that volume's files.
When you open the Trash icon on your desktop, what you're seeing in there is really the contents of _all_ the Trash folders on _all_ the currently mounted volumes (possibly excepting remote network volumes: see below). When you drag an item to the trash in the Finder, it gets stored into the Trash directory that resides on that item's own volume.
When you think about it, this is perfectly consistent with the Trash's role as a "temporary" disposal site. Suppose I inserted a floppy, then dragged one of the floppy's files, "Letter from ex-girlfriend" to the trash. I do _not_ expect that file to be totally wiped from the floppy. I expect to be able to take that floppy to another Mac, insert it, and see "Letter from ex-girlfriend" in the Trash on that desktop. I then expect to be able to select "Put away," and have that file restored to its previous location on the floppy.
Having said all that, I think the rules are a bit different when it comes to volumes which are remote servers. When you mount a server, you can't see any of that server's existing Trash'ed items in your local Trash, and if you trash any of the remote files while connected, they show up in your local Trash but don't show up if you go sit at the server and open _its_ trash. As to where the trashed file _really_ is at this point, I'm not sure. I don't know if it literally gets copied to the local machine, or something akin to an alias gets put there. If you're trashing remote files programmatically, I couldn't hazard a guess as to the HIG'ly correct thing to do.
It definitely does _not_ get copied locally; trashing a 4Mb file from fbo last night (then emptying the trash) took only a few seconds. Downloading it took many minutes.
I think the files _will_ appear in the server's Trash sometimes, though not always, but I'm not sure what it's dependent on. When my desktop Mac at work was running as a server, I'd sometimes come in and find things in the trash that I didn't put there, which implies that someone did so "remotely".
Network file servers have an invisible "Network Trash" folder. In this folder are an invisible "Trash Can Usage Map" file (a private file maintained and used by the file server software) and additional folders ("Network Trash Can #1," "Network Trash Can #2," etc). These folders are created and deleted dynamically.
When a file on a networked file server is placed in the trash, a Network Trash Can folder is created for that workstation, and the file is moved into it. The data structures in the Trash Can Usage Map file are used by the file server to track which client machine "owns" which trash can folder.
If your file server is a non-MacOS machine (for example, if you're running a Sun SPARCstation with Helios EtherShare installed), you can cd to those directories and see the files in them.
If a workstation crashes, the files remain in the network trash can folders until the server is restarted; during restart, the files are deleted. If a workstation disconnects from the server in an orderly way, or the workstation's user empties the trash, the files are deleted immediately.