Professional Web Applications Themes

getting a user's trash folders - Mac Programming

I want to get the current user's trash folders. As far as I understand it the items in the trash live not just in ~/.Trash, but also in folders on other volumes than the startup volume. If tried to find more info on these locations, but I couldn't find it on developer.apple.com or on usenet. Now, generally it's best to get the location of these folders from the system, at runtime. I've looked into: (1) COCOA NSArray *NSSearchPathForDirectoriesInDomains ( NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL expandTilde) This looked promissing, but there is no NSSearchPathDirectory value for the trash folders ( but ...

  1. #1

    Default getting a user's trash folders

    I want to get the current user's trash folders. As far as I understand
    it the items in the trash live not just in ~/.Trash, but also in folders
    on other volumes than the startup volume. If tried to find more info on
    these locations, but I couldn't find it on developer.apple.com or on
    usenet.

    Now, generally it's best to get the location of these folders from the
    system, at runtime. I've looked into:

    (1) COCOA
    NSArray *NSSearchPathForDirectoriesInDomains (
    NSSearchPathDirectory directory,
    NSSearchPathDomainMask domainMask,
    BOOL expandTilde)

    This looked promissing, but there is no NSSearchPathDirectory value for
    the trash folders ( but there is a NSDemoApplicationDirectory value...
    ). So although this probably should be the way to get an array of trash
    paths, NSTrashDirectory is missing.

    (2) CARBON
    OSErr FSFindFolder (
    short vRefNum,
    OSType folderType,
    Boolean createFolder,
    FSRef *foundRef
    )

    Here, there are 3 possible values for 'folderType':
    - kTrashFolderType = 'trsh',
    - kSystemTrashFolderType = 'strs',
    - kWhereToEmptyTrashFolderType = 'empt',
    none of which gives my anything different from ~/.Trash, and
    kSystemTrashFolderType, (which isn't docented) just gives me a
    sigsegv. Also, how would I get the _collection_ of paths using this
    call?

    So, this is what I know sofar. How do I robustly get the paths to a
    users trashed files?

    Patrick
    Patrick Guest

  2. #2

    Default Re: getting a user's trash folders

    In article <1gh6aj6.1uluvng71m328N%nl>,
    nl (Patrick Machielse) wrote:
     

    For the volumes hosting ~, the trash is in "~/.Trash".
    For every local volumes other than that, the trash is in
    "/Volumes/<volname>/.Trashes/<uid>"
    For networked volumes, trashed items are deleted immediately.

    G

    --
    Standard output is like your butt. Everyone has one. When using a bathroom,
    they all default to going into a toilet. However, a person can redirect his
    "standard output" to somewhere else, if he so chooses. - Jeremy Nixon
    Gregory Guest

  3. #3

    Default Re: getting a user's trash folders

    In article <1gh6aj6.1uluvng71m328N%nl>,
    nl (Patrick Machielse) wrote:
     

    This is tho one you want.

    For user's files in the home directory, pass kUserDomain for the first
    parameter. For other volumes, use the actual volume reference number,
    like this:

    // path = some valid path to a file/folder on a secondary volume
    FSRef file;
    FSPathMakeRef(path, &file, NULL);
    FSCatalogInfo info;
    FSGetCatalogInfo(&file, kFSCatInfoVolume, &info, 0, 0, 0);
    FSFindFolder(info.volume, 'trsh', false, &file);

    This should give you the trash folder for that volume, but be sure to
    check all the error codes because not every kind of volume uses a trash
    folder.

    -Chad
    Chad Guest

  4. #4

    Default Re: getting a user's trash folders

    Gregory Weston <com> wrote:
     
    >
    > For the volumes hosting ~, the trash is in "~/.Trash".
    > For every local volumes other than that, the trash is in
    > "/Volumes/<volname>/.Trashes/<uid>"
    > For networked volumes, trashed items are deleted immediately.[/ref]

    Thanks, that seems to be right. Do you by any chance have a URL to
    Apple's doentation?

    Patrick
    Patrick Guest

  5. #5

    Default Re: getting a user's trash folders

    Chad M <andthistoo.insightbb.com> wrote:
     

    Thanks Chad, I'll check this out. It seems that I have to do most of the
    work myself:

    - enumerate the volumes
    - single out the volume with the user's home folder
    (may not be the startup volume)
    - use FSFolder and check return value.

    In the end it should be more robust than constructing the paths 'by
    hand' though.

    I think I will file an enhancement request for
    NSSearchPathForDirectoriesInDomains because I think it really should
    support getting the trash folders.

    Patrick
    Patrick Guest

  6. #6

    Default Re: getting a user's trash folders

    In article <1gh7xop.11l94trbcvhz2N%nl>,
    nl (Patrick Machielse) wrote:
     
    > >
    > > For the volumes hosting ~, the trash is in "~/.Trash".
    > > For every local volumes other than that, the trash is in
    > > "/Volumes/<volname>/.Trashes/<uid>"
    > > For networked volumes, trashed items are deleted immediately.[/ref]
    >
    > Thanks, that seems to be right. Do you by any chance have a URL to
    > Apple's doentation?[/ref]

    This is not doented. It has changed in the past. You would be foolish to rely
    on it. Also, it is not entirely correct, as AFP support server trash, and does
    not require trashed items on network volumes to be deleted immediately.

    Do not hardcode these names into your code. At the very least, you should use
    "kSystemTrashFolderType" and "kTrashFolderType", iterating over volumes.
    However, you should note that even with administrative privileges you may not
    have permission to read, much less modify, every conceivable trash on every
    accessible volume.

    Which brings me to my main point: what are you really trying to do?

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  7. #7

    Default Re: getting a user's trash folders

    Miro Jurisic <org> wrote:
     
    >
    > This is not doented. It has changed in the past. You would be foolish
    > to rely on it. Also, it is not entirely correct, as AFP support server
    > trash, and does not require trashed items on network volumes to be deleted
    > immediately.[/ref]

    A doentation enhancement request seems to be in order, then.
     

    What is the best way to iterate over the mounted volumes? (is there a
    standard way to do this in Carbon. I don't want to link with AppKit (for
    NSWorkSpace) )
     

    I'm writing an app that manages the trash for the current user. So I'm
    really only interested in the trash locations for that user. Sofar my
    code looks like this:

    // get an array of paths to user trash folders
    NSMutableArray *trashes = [NSMutableArray array];

    // enumerate volumes on mount point /Volumes/
    NSEnumerator *e = [[self mountedVolumes] objectEnumerator];
    NSString *volumePath;
    while ( volumePath = [e nextObject] ) {
    // make volume FSRef
    FSRef volRef;
    if (noErr != FSPathMakeRef([volumePath UTF8String], &volRef, NULL))
    continue;

    // get volume info from volume FSRef
    FSCatalogInfo info;
    if (noErr != FSGetCatalogInfo(&volRef, kFSCatInfoVolume, &info,
    NULL, NULL, NULL))
    continue;

    // get trash FSRef on the volume
    FSRef trashRef;
    if (noErr != FSFindFolder(info.volume, kTrashFolderType,
    kDontCreateFolder, &trashRef))
    continue;

    // add path from trash FSRef to 'trashes'
    UInt8 path[256];
    if (noErr == FSRefMakePath(&trashRef, path, 255)) {
    [trashes addObject:[NSString stringWithUTF8String:(const char
    *)path]];
    }
    }

    where [self mountedVolumes] returns an array of volume names (like
    "/Volumes/startup" etc.). I'm not sure about the last step, turning the
    UInt8 array into an NSString, but I believe this is the right way, and
    sofar it works...

    Patrick
    Patrick Guest

  8. #8

    Default Re: getting a user's trash folders

    In article <1gh9vfg.1d1ibsq1fv4sv4N%nl>,
    nl (Patrick Machielse) wrote:
     
    > >
    > > This is not doented. It has changed in the past. You would be foolish
    > > to rely on it. Also, it is not entirely correct, as AFP support server
    > > trash, and does not require trashed items on network volumes to be deleted
    > > immediately.[/ref]
    >
    > A doentation enhancement request seems to be in order, then.[/ref]

    For what? I didn't see any place in Apple doentation where names of trash
    folders were listed...
     
    >
    > What is the best way to iterate over the mounted volumes? (is there a
    > standard way to do this in Carbon. I don't want to link with AppKit (for
    > NSWorkSpace) )[/ref]

    FSGetVolumeInfo

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

Similar Threads

  1. Replies: 4
    Last Post: April 7th, 06:49 PM
  2. Distiller sends files to user/.trash folder
    By Jessica_Scholl@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: August 4th, 04:15 PM
  3. How to delete old user profiles and folders?
    By Renee in forum Windows Setup, Administration & Security
    Replies: 4
    Last Post: July 23rd, 06:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139