Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C equivalent of cp, cpmac or ditto ?

10 views
Skip to first unread message

mhz

unread,
Oct 27, 2006, 8:15:44 AM10/27/06
to
C equivalent of cp, cpmac or ditto ?
Does such thing exist?

Gregory Weston

unread,
Oct 27, 2006, 9:51:07 PM10/27/06
to
In article <none-BDF685.0...@news.videotron.net>,
mhz <no...@nowhere.ca> wrote:

> C equivalent of cp, cpmac or ditto ?
> Does such thing exist?

cp, cpmac, and ditto are all implemented as a sequence of commands that
accomplish the objective of duplicating files while coping with most, if
not all, error conditions that might reasonably arise. If you really
want, you can execute shell commands through any of several mechanisms,
but which one makes most sense depends quite a bit on the nature of the
rest of your project.

--
What I write is what I mean. I request that anyone who decides to respond
please refrain from "disagreeing" with something I didn't write in the first
place.

David Phillip Oster

unread,
Oct 28, 2006, 12:13:47 AM10/28/06
to

> C equivalent of cp, cpmac or ditto ?
> Does such thing exist?

If you can stand linking to the Foundation Objective C library, take a
look at

NSFileManager *fm = [NSFileManager defaultManager];
if ([fm copyParth:src toPath:dest handler:nil]) {
}

You can also probably use NSURLDownload with @"file:///Users/..." URLs

Michael Ash

unread,
Oct 28, 2006, 8:45:29 AM10/28/06
to

It's doubtful that the NSURLDownload will copy all of the relevant
metadata, or that it will work with directories. NSFileManager will do
fine, though.

If you don't like Objective-C, you can use FSCopyObjectSync.

--
Michael Ash
Rogue Amoeba Software

Patrick Machielse

unread,
Oct 28, 2006, 5:14:20 PM10/28/06
to
Michael Ash <mi...@mikeash.com> wrote:

> David Phillip Oster <os...@ieee.org> wrote:
>
> > If you can stand linking to the Foundation Objective C library, take a
> > look at
> >
> > NSFileManager *fm = [NSFileManager defaultManager];
> > if ([fm copyParth:src toPath:dest handler:nil]) {
> > }
> >
> > You can also probably use NSURLDownload with @"file:///Users/..." URLs
>
> It's doubtful that the NSURLDownload will copy all of the relevant
> metadata, or that it will work with directories. NSFileManager will do
> fine, though.

You can perform file operations with NSWorkspace. Its main distinctive
feature (as fas as I can see) is that it can move files into the trash.

patrick

Michael Ash

unread,
Oct 28, 2006, 5:35:57 PM10/28/06
to

I have heard that this feature is broken, although I don't exactly recall
and I've never tested it. Beware when writing code that uses this, and
test it in weird situations like external drives, network volumes, etc.
The Trash is a complicated place.

Patrick Machielse

unread,
Oct 28, 2006, 7:22:39 PM10/28/06
to
Michael Ash <mi...@mikeash.com> wrote:

> > You can perform file operations with NSWorkspace. Its main distinctive
> > feature (as fas as I can see) is that it can move files into the trash.
>
> I have heard that this feature is broken, although I don't exactly recall
> and I've never tested it. Beware when writing code that uses this, and
> test it in weird situations like external drives, network volumes, etc.
> The Trash is a complicated place.

Thanks for the warning. (We _must_ demand public access to Bug Tracker!)
I must say I have not experienced anything wrong while using NSWorkspace
for trashing files.

I'm not sure why NSWorkspace duplicates functionality found in
NSFileManager. Maybe it will automatically call noteFileSystemChanged:
after the operation, but the documentations doesn't say so.

patirck

Michael Ash

unread,
Oct 28, 2006, 10:48:39 PM10/28/06
to
Patrick Machielse <nor...@mail.invalid> wrote:
>
> Thanks for the warning. (We _must_ demand public access to Bug Tracker!)

File a bug about it. :)

> I must say I have not experienced anything wrong while using NSWorkspace
> for trashing files.

I could always be wrong.

> I'm not sure why NSWorkspace duplicates functionality found in
> NSFileManager. Maybe it will automatically call noteFileSystemChanged:
> after the operation, but the documentations doesn't say so.

I suspect it's for consistency. You already have a bunch of operations
that NSFileManager can't do, you might as well throw in a couple that it
can do. But NSWorkspace can't substitute for NSFileManager because
NSFileManager has a bunch of other stuff, and NSWorkspace is in AppKit,
not Foundation.

If you want duplicated functionality, look at URL loading. I haven't
really counted, but there are probably at least a half-dozen ways to load
the contents of a URL, most of them broken in different and interesting
ways.

0 new messages