Welcome to Soft32 Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

getting a user's trash folders

 
   Soft32 Home -> Mac -> Programmer Help RSS
Next:  NSOutlineView setDataSource -> exception  
Author Message
Patrick Machielse

External


Since: Aug 16, 2003
Posts: 48



(Msg. 1) Posted: Mon Jul 19, 2004 8:43 am
Post subject: getting a user's trash folders
Archived from groups: comp>sys>mac>programmer>help (more info?)

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 doccumented) 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
Back to top
Login to vote
Gregory Weston

External


Since: Sep 10, 2004
Posts: 1029



(Msg. 2) Posted: Mon Jul 19, 2004 8:43 am
Post subject: Re: getting a user's trash folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

> 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.

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
Back to top
Login to vote
Chad M

External


Since: Jul 19, 2004
Posts: 3



(Msg. 3) Posted: Mon Jul 19, 2004 12:48 pm
Post subject: Re: getting a user's trash folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

> (2) CARBON
> OSErr FSFindFolder (
> short vRefNum,
> OSType folderType,
> Boolean createFolder,
> FSRef *foundRef
> )
>
> Here, there are 3 possible values for 'folderType':
> - kTrashFolderType = 'trsh',

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
Back to top
Login to vote
Patrick Machielse

External


Since: Aug 16, 2003
Posts: 48



(Msg. 4) Posted: Tue Jul 20, 2004 6:14 am
Post subject: Re: getting a user's trash folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Gregory Weston <gwestonREMOVE.TakeThisOut@CAPSattbi.com> wrote:

> (Patrick Machielse) wrote:
>
> > I want to get the current user's trash folders.
>
> 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.

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

Patrick
Back to top
Login to vote
Patrick Machielse

External


Since: Aug 16, 2003
Posts: 48



(Msg. 5) Posted: Tue Jul 20, 2004 6:14 am
Post subject: Re: getting a user's trash folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Chad M <huskerchad.DeleteThis@removethis.andthistoo.insightbb.com> wrote:

> 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.

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
Back to top
Login to vote
Miro Jurisic

External


Since: May 10, 2004
Posts: 1194



(Msg. 6) Posted: Tue Jul 20, 2004 6:14 am
Post subject: Re: getting a user's trash folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1gh7xop.11l94trbcvhz2N%noreply@dds.nl>,
noreply DeleteThis @dds.nl (Patrick Machielse) wrote:

> Gregory Weston <gwestonREMOVE DeleteThis @CAPSattbi.com> wrote:
>
> > (Patrick Machielse) wrote:
> >
> > > I want to get the current user's trash folders.
> >
> > 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.
>
> Thanks, that seems to be right. Do you by any chance have a URL to
> Apple's documentation?

This is not documented. 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>
Back to top
Login to vote
Patrick Machielse

External


Since: Aug 16, 2003
Posts: 48



(Msg. 7) Posted: Wed Jul 21, 2004 9:48 am
Post subject: Re: getting a user's trash folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Miro Jurisic <macdev.RemoveThis@meeroh.org> wrote:

> > Thanks, that seems to be right. Do you by any chance have a URL to
> > Apple's documentation?
>
> This is not documented. 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.

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

> Do not hardcode these names into your code. At the very least, you should use
> "kSystemTrashFolderType" and "kTrashFolderType", iterating over volumes.

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) )

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

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
Back to top
Login to vote
Miro Jurisic

External


Since: May 10, 2004
Posts: 1194



(Msg. 8) Posted: Wed Jul 21, 2004 10:34 am
Post subject: Re: getting a user's trash folders [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <1gh9vfg.1d1ibsq1fv4sv4N%noreply@dds.nl>,
noreply.TakeThisOut@dds.nl (Patrick Machielse) wrote:

> Miro Jurisic <macdev.TakeThisOut@meeroh.org> wrote:
>
> > > Thanks, that seems to be right. Do you by any chance have a URL to
> > > Apple's documentation?
> >
> > This is not documented. 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.
>
> A documentation enhancement request seems to be in order, then.

For what? I didn't see any place in Apple documentation where names of trash
folders were listed...

> > Do not hardcode these names into your code. At the very least, you should
> > use "kSystemTrashFolderType" and "kTrashFolderType", iterating over
> > volumes.
>
> 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) )

FSGetVolumeInfo

meeroh

--
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to get the user and group ID? - Dear All How do you get the user ID and the group ID? I have a function to get the IDs from a file, but when I not the...

multilanguage changeable by the user? - Hello My application is translated to several languages. The language-dependant resources 'MENU', 'STR#', 'STR ' and s...

Allow openPanel to choose folders in Cocoa document-based .. - I am trying to figure out the best way to force the open panel of a Cocoa document-based application to allow selectio...

Xcode user interface documentation - I just upgraded to Panther and installed the latest development tools which includes Xcode. The user interface for Xco...

Running a thread as a different user under cocoa - I'm using cocoa and objective-C to write a front end to some command line tools which need to run as a different user ...

email address from the current user - Dear all How I can get the email address from the current user? Give it a possibility? I have only found function to...
       Soft32 Home -> Mac -> Programmer Help All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum

Categories:
 Windows
 Linux
  Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]