Safe Filename Characters

Discussion in 'Mac Programming' started by Sydde, Feb 2, 2010.

  1. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #1
    I want to do some file transfers, and I would rather not bother the user with "replace?" alerts. One option will be to just use the trash, but I also want to offer the option of tacking on a character (or characters) to the end of the file name to mark the new file. What characters would be terminal-safe? One I am considering in "_" (old file would be "file.ext", new file would be "file_.ext", adding underscores until the name is unique). Are "@", "^", "~" or "`" good alternatives? (One character for file names, another for links/aliases.)
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    I recommend "file-N.ext", where N is a series of increasing numbers, "1", "2", etc.

    Avoid special characters because the target filesystem might not like them. Or the OS that eventually reads the filesystem might not.

    And all characters are Terminal-safe, when quoted (yes, even quotes, when quoted or escaped). The advantage of avoiding specials and spaces is you don't have to force the user to add quoting due to the uniquefying part.
     
  3. zeppenwolf macrumors regular

    zeppenwolf

    Joined:
    Nov 17, 2009
    #3
    If the situation is that there will be a maximum of one "old" file, (you won't need 1,2,3...) then I have the feeling that "~filename" is an old answer to the problem.

    But I can't remember where I get that feeling from.... emacs?
     

Share This Page