Re: Length of a filename
Re: Length of a filename
- Subject: Re: Length of a filename
- From: "Michael Ash" <email@hidden>
- Date: Thu, 16 Oct 2008 10:25:12 -0400
On Thu, Oct 16, 2008 at 5:31 AM, Gerriet M. Denkmann
<email@hidden> wrote:
>
> How can I check the appositeness of a filename?
>
> This will not work:
> if ( [potentialPath length] > 255 ) ... error: filename too long
> because HFS+ uses some decomposed form.
>
> This might work:
> if ( [[ NSString stringWithUTF8String: [potentialPath
> fileSystemRepresentation] ] length] > 255 ) ...
> but looks kind of convoluted and inefficient.
>
> There are two methods in NSString:
> decomposedStringWithCanonicalMapping
> decomposedStringWithCompatibilityMapping
> but the documentation does not say which (if any) should be used to convert
> a potentialPath into a form used in HFS+.
It is impossible to preflight a filename in the general case, because
HFS+ is not the only filesystem in the universe. You could be writing
to FAT32 or ZFS or HFS or something else, all of which have different
rules for what's allowed and what's not. Even worse, you could be
writing to a network filesystem that is backed by anything, and you
can't even find out what that is.
If you need to know whether a filename is legal, the only sure way is
to try it and see if it works. If you need to preflight before you do
some "real" work, the only way I've found is to write out a dummy file
first and see if that succeeds.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden