4

What characters are illegal on the filename on iOS or OS X?

For example, char "/" is illegal. I need to remove all of them and only them.

Dmitry
  • 14,306
  • 23
  • 105
  • 189
  • Possible duplicate of [http://superuser.com/questions/326103/mac-os-x-lion-what-are-invalid-characters-for-a-file-name](http://superuser.com/questions/326103/mac-os-x-lion-what-are-invalid-characters-for-a-file-name) –  Jan 03 '14 at 23:36
  • I needs to be noted that OS X ignores case while iOS doesn't. – Hot Licks Jan 03 '14 at 23:36
  • 3
    @HotLicks OS X can be setup with a case-sensitive filesystem like iOS. It all depends on the filesystem you choose when formatting a partition. – rmaddy Jan 03 '14 at 23:39
  • Illegal? No one is going to arrest you. Invalid, perhaps. – bmargulies Jan 04 '14 at 13:54

2 Answers2

6

Illegal characters on the HFS file system:

  • : - illegal char.
  • / - it's poor to use it.
  • \0 - not sure, but don't use it too.
Dmitry
  • 14,306
  • 23
  • 105
  • 189
  • Only `:` is illegal. `/` is the path separator and `\0` terminates the string, so is impossible to use. – trojanfoe Jan 04 '14 at 10:40
  • trojanfoe: HFS+ uses Pascal strings, not C strings, so `\0` is perfectly legal. TN1150 even describes the rules for how they are sorted: http://dubeiko.com/development/FileSystems/HFSPLUS/tn1150.html#HFSPlusNames – Ssswift Apr 20 '17 at 17:27
0

It is the same as any *nix filesystem. See this post: What characters should be restricted from a Unix file name?

Community
  • 1
  • 1
coneybeare
  • 33,113
  • 21
  • 131
  • 183
  • 1
    iOS and OS X uses HFS or HFS+ file system with its own restrictions. – Dmitry Jan 03 '14 at 23:38
  • Why I can't use ":" on the Finder app? – Dmitry Jan 03 '14 at 23:39
  • It looks like it's the same: http://superuser.com/questions/204287/what-characters-are-forbidden-in-os-x-filenames – coneybeare Jan 03 '14 at 23:44
  • Check out the first comment on the accepted answer – coneybeare Jan 03 '14 at 23:45
  • 1
    @Altaveron: The OS X Finder translates "/" from to UI to ":" in the file system. So from the user's view, "/" is an allowed character but ":" it not. The reason is probably historical. The old Macintosh file manager functions (I don't remember what they were called exactly) used ":" as the path separator. – Martin R Jan 03 '14 at 23:59
  • I think you are not right. I can't use ":" on Finder and can use "/". – Dmitry Jan 04 '14 at 10:26