Possible Bug in NSFileManager -moveItemAtPath:toPath:error:

  • Hi Guys,

    Just a quick one.  I would expect renaming a file named HELLO.TXT to
    hello.txt (or another variant where the case of a few letters change)
    with -moveItemAtPath:toPath:error: to be allowed.  As it is not (it
    generates an NSFileWriteUnknownError) is this a bug or just me?  If
    not, is there are more appropriate API for renaming files?

    Thanks,

    Jon
  • On May 31, 2008, at 18:27, Jonathan Dann wrote:

    > Hi Guys,
    >
    > Just a quick one.  I would expect renaming a file named HELLO.TXT to
    > hello.txt (or another variant where the case of a few letters
    > change) with -moveItemAtPath:toPath:error: to be allowed.  As it is
    > not (it generates an NSFileWriteUnknownError) is this a bug or just
    > me?  If not, is there are more appropriate API for renaming files?

    Have you tried:

    HELLO.TXT -> something
    something -> hello.txt

    Just a thought ....maybe it's related to the filesystem no being case-
    sensitive.

    cheers
    --
    Torsten
  • On 31 May '08, at 9:27 AM, Jonathan Dann wrote:

    > Just a quick one.  I would expect renaming a file named HELLO.TXT to
    > hello.txt (or another variant where the case of a few letters
    > change) with -moveItemAtPath:toPath:error: to be allowed. As it is
    > not (it generates an NSFileWriteUnknownError) is this a bug or just
    > me?

    That ought to work, even on HFS+. (It's not a no-op, because HFS+
    preserves the case of filenames, so getting the directory contents
    will return the name in its new case.)

    > If not, is there are more appropriate API for renaming files?

    Try using the system call "rename". (Use "man 2 rename" to see the
    documentation.)
    Call -fileSystemRepresentation on your path strings to convert them to
    appropriate C strings.

    —Jens
  • On 31 May 2008, at 17:37, Torsten Curdt wrote:

    >
    > On May 31, 2008, at 18:27, Jonathan Dann wrote:
    >
    >> Hi Guys,
    >>
    >> Just a quick one.  I would expect renaming a file named HELLO.TXT
    >> to hello.txt (or another variant where the case of a few letters
    >> change) with -moveItemAtPath:toPath:error: to be allowed.  As it is
    >> not (it generates an NSFileWriteUnknownError) is this a bug or just
    >> me?  If not, is there are more appropriate API for renaming files?
    >
    > Have you tried:
    >
    > HELLO.TXT -> something
    > something -> hello.txt
    >
    > Just a thought ....maybe it's related to the filesystem no being
    > case-sensitive.
    >
    > cheers
    > --
    > Torsten

    Thanks Torsten that works, just feels like a hack as I have to use
    another method to generate a filename that isn't in the working
    directory.

    Jon
  • On 31 May 2008, at 18:17, Jens Alfke wrote:

    >
    > On 31 May '08, at 9:27 AM, Jonathan Dann wrote:
    >
    >> Just a quick one.  I would expect renaming a file named HELLO.TXT
    >> to hello.txt (or another variant where the case of a few letters
    >> change) with -moveItemAtPath:toPath:error: to be allowed. As it is
    >> not (it generates an NSFileWriteUnknownError) is this a bug or just
    >> me?
    >
    > That ought to work, even on HFS+. (It's not a no-op, because HFS+
    > preserves the case of filenames, so getting the directory contents
    > will return the name in its new case.)
    >
    >> If not, is there are more appropriate API for renaming files?
    >
    > Try using the system call "rename". (Use "man 2 rename" to see the
    > documentation.)
    > Call -fileSystemRepresentation on your path strings to convert them
    > to appropriate C strings.
    >
    > —Jens

    I'll have a look at that, would that break if my users have non-ascii
    filenames?  I've only worked with NString, which handles Unicode
    transparently.

    Thanks Jens,

    Jon
  • On Sat, May 31, 2008 at 4:35 PM, Jonathan Dann <j.p.dann...> wrote:
    > On 31 May 2008, at 18:17, Jens Alfke wrote:
    >> Try using the system call "rename". (Use "man 2 rename" to see the
    >> documentation.)
    >> Call -fileSystemRepresentation on your path strings to convert them to
    >> appropriate C strings.
    >
    > I'll have a look at that, would that break if my users have non-ascii
    > filenames?  I've only worked with NString, which handles Unicode
    > transparently.

    As long as you use fileSystemRepresentation, it always does The Right
    Thing w.r.t. Unicode encoding.
  • On 31 May 2008, at 22:51, stephen joseph butler wrote:

    > On Sat, May 31, 2008 at 4:35 PM, Jonathan Dann <j.p.dann...>
    > wrote:
    >> On 31 May 2008, at 18:17, Jens Alfke wrote:
    >>> Try using the system call "rename". (Use "man 2 rename" to see the
    >>> documentation.)
    >>> Call -fileSystemRepresentation on your path strings to convert
    >>> them to
    >>> appropriate C strings.
    >>
    >> I'll have a look at that, would that break if my users have non-ascii
    >> filenames?  I've only worked with NString, which handles Unicode
    >> transparently.
    >
    > As long as you use fileSystemRepresentation, it always does The Right
    > Thing w.r.t. Unicode encoding.

    Awesome! Thanks for your help.

    Jon
previous month may 2008 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Go to today