views:

50

answers:

2

Anyone know how to test if a string is a valid file name in Mac OS X, other than trying to create file with that name?

The issue I'm having is that sometimes, a file name can be too large. OSX has a byte limit for filenames and with unicode characters you can't just check the length of the string since they can be more than 1 byte.

A: 

I think the only invalid character (except control chars) on OSX is the colon - so you simply have to test if the new filename contains colons.

heb
A: 

Use NSFileManager.

-- Updated:

Try this:

if([testPath compare: [NSString stringWithUTF8String:[testPath fileSystemRepresentation]]] == NSOrderedSame) {
    //testPath is a valid Path
}

No guarantees on what it will do though.

Stephen Furlani
I need to know if a file name is valid, not if the file already exists.
Randall
Try this `[NSString stringWithUTF8String:[myPath fileSystemRepresentation]];`
Stephen Furlani