How to rename a filename in uppercase

  • Hi,
    i've a question. I'm trying to write some code that make a filename in
    uppercase. i wrote a thing like that:
    [defaultManager movePath:@"foo.txt" toPath:@"FOO.txt" handler:nil];

    this code doesn't work because cocoa seems to be case-sensitive and
    this method is useless for my pourpose. So, i need a method like the
    unix mv, in fact if i use the command mv foo.txt FOO.txt , everything
    is allright.
    Someone have a smart idea to do this? Or i need to use two renaming?
    Like this (a very bad idea):
    [defaultManager movePath:@"foo.txt" toPath:@"temp.txt" handler:nil];
    [defaultManager movePath:@"temp.txt" toPath:@"FOO.txt" handler:nil];

    Thanks

    Simo
  • On 20 Jan 2008, at 17:36, Simone Tessaro wrote:

    > Hi,
    > i've a question. I'm trying to write some code that make a filename in
    > uppercase. i wrote a thing like that:
    > [defaultManager movePath:@"foo.txt" toPath:@"FOO.txt" handler:nil];

    What happens if you implement a handler? Any indication of why it
    might be failing?
    >
    >
    > this code doesn't work because cocoa seems to be case-sensitive and
    > this method is useless for my pourpose. So, i need a method like the
    > unix mv, in fact if i use the command mv foo.txt FOO.txt , everything
    > is allright.
    > Someone have a smart idea to do this? Or i need to use two renaming?
    > Like this (a very bad idea):
    > [defaultManager movePath:@"foo.txt" toPath:@"temp.txt" handler:nil];
    > [defaultManager movePath:@"temp.txt" toPath:@"FOO.txt" handler:nil];

    Well does this actually work for you if you try it?
  • These look like filenames, not full paths. You can't supply a partial
    path here.

    Simone Tessaro wrote:
    > Hi,
    > i've a question. I'm trying to write some code that make a filename in
    > uppercase. i wrote a thing like that:
    > [defaultManager movePath:@"foo.txt" toPath:@"FOO.txt" handler:nil];
    >
    > this code doesn't work because cocoa seems to be case-sensitive and
    > this method is useless for my pourpose. So, i need a method like the
    > unix mv, in fact if i use the command mv foo.txt FOO.txt , everything
    > is allright.
    > Someone have a smart idea to do this? Or i need to use two renaming?
    > Like this (a very bad idea):
    > [defaultManager movePath:@"foo.txt" toPath:@"temp.txt" handler:nil];
    > [defaultManager movePath:@"temp.txt" toPath:@"FOO.txt" handler:nil];
    >
    > Thanks
    >
    > Simo
    >
  • 2008/1/20, John Stiles <jstiles...>:
    > These look like filenames, not full paths. You can't supply a partial
    > path here.

    sure. the path is omitted. but is present in the real code..
    in fact the real code is like that:
    [defaultManager movePath:@"/User/username/Desktop/foo.txt"
    toPath:@"/User/username/Desktop/FOO.txt"" handler:nil];

    sorry for the lack of precision..

    S.
  • 2008/1/20, Mike Abdullah <cocoadev...>:
    >
    > On 20 Jan 2008, at 17:36, Simone Tessaro wrote:
    >
    >> Hi,
    >> i've a question. I'm trying to write some code that make a filename in
    >> uppercase. i wrote a thing like that:
    >> [defaultManager movePath:@"foo.txt" toPath:@"FOO.txt" handler:nil];
    >
    > What happens if you implement a handler? Any indication of why it
    > might be failing?

    I did it. and this is the result:
    {Error = "Already Exists"; Path = "/Users/username/Desktop/foo.txt"; }

    so the problem could be something about the case-sensitiveness.

    >>
    >>
    >> this code doesn't work because cocoa seems to be case-sensitive and
    >> this method is useless for my pourpose. So, i need a method like the
    >> unix mv, in fact if i use the command mv foo.txt FOO.txt , everything
    >> is allright.
    >> Someone have a smart idea to do this? Or i need to use two renaming?
    >> Like this (a very bad idea):
    >> [defaultManager movePath:@"foo.txt" toPath:@"temp.txt" handler:nil];
    >> [defaultManager movePath:@"temp.txt" toPath:@"FOO.txt" handler:nil];
    >
    > Well does this actually work for you if you try it?

    Nothing. but i think there's a better solution.. more elegant

    Thanks

    S.
  • On Jan 20, 2008, at 11:15 AM, John Stiles wrote:

    > These look like filenames, not full paths. You can't supply a
    > partial path here.

    Yes, you can supply partial paths.  See -[NSFileManager
    currentDirectoryPath].

    adam

    >
    >
    >
    > Simone Tessaro wrote:
    >> Hi,
    >> i've a question. I'm trying to write some code that make a filename
    >> in
    >> uppercase. i wrote a thing like that:
    >> [defaultManager movePath:@"foo.txt" toPath:@"FOO.txt" handler:nil];
    >>
    >> this code doesn't work because cocoa seems to be case-sensitive and
    >> this method is useless for my pourpose. So, i need a method like the
    >> unix mv, in fact if i use the command mv foo.txt FOO.txt , everything
    >> is allright.
    >> Someone have a smart idea to do this? Or i need to use two renaming?
    >> Like this (a very bad idea):
    >> [defaultManager movePath:@"foo.txt" toPath:@"temp.txt" handler:nil];
    >> [defaultManager movePath:@"temp.txt" toPath:@"FOO.txt" handler:nil];
    >>
    >> Thanks
    >>
    >> Simo
    >>

  • Well, OK, you're right, but I just simplified this issue a bit rather
    than explain the details of current directories, and how Xcode and the
    Finder don't have the same directory when the app starts, and etc etc.
    It's more complicated than it should be, so it's easiest to just say
    "use full paths."

    Adam R. Maxwell wrote:
    >
    > On Jan 20, 2008, at 11:15 AM, John Stiles wrote:
    >
    >> These look like filenames, not full paths. You can't supply a partial
    >> path here.
    >
    > Yes, you can supply partial paths.  See -[NSFileManager
    > currentDirectoryPath].
    >
    > adam
    >
    >>
    >>
    >>
    >> Simone Tessaro wrote:
    >>> Hi,
    >>> i've a question. I'm trying to write some code that make a filename in
    >>> uppercase. i wrote a thing like that:
    >>> [defaultManager movePath:@"foo.txt" toPath:@"FOO.txt" handler:nil];
    >>>
    >>> this code doesn't work because cocoa seems to be case-sensitive and
    >>> this method is useless for my pourpose. So, i need a method like the
    >>> unix mv, in fact if i use the command mv foo.txt FOO.txt , everything
    >>> is allright.
    >>> Someone have a smart idea to do this? Or i need to use two renaming?
    >>> Like this (a very bad idea):
    >>> [defaultManager movePath:@"foo.txt" toPath:@"temp.txt" handler:nil];
    >>> [defaultManager movePath:@"temp.txt" toPath:@"FOO.txt" handler:nil];
    >>>
    >>> Thanks
    >>>
    >>> Simo
    >>>

    >
  • On Jan 20, 2008, at 1:27 PM, Simone Tessaro wrote:

    > 2008/1/20, Mike Abdullah <cocoadev...>:
    >>
    >> On 20 Jan 2008, at 17:36, Simone Tessaro wrote:
    >>
    >>> Hi,
    >>> i've a question. I'm trying to write some code that make a
    >>> filename in
    >>> uppercase. i wrote a thing like that:
    >>> [defaultManager movePath:@"foo.txt" toPath:@"FOO.txt" handler:nil];
    >>
    >> What happens if you implement a handler? Any indication of why it
    >> might be failing?
    >
    > I did it. and this is the result:
    > {Error = "Already Exists"; Path = "/Users/username/Desktop/foo.txt"; }
    >
    > so the problem could be something about the case-sensitiveness.

    This will only work if the underlying file system is case sensitive.
    HFS just plays a case sensitive file system on TV, but in reality it
    is not.

    Simple test: In a terminal window go to some directory and

    touch foo
    touch FOO

    On a real cases sensitive file system you end up with 2 files, foo and
    FOO. But on most file systems OS X systems use, it will be just 1 file.

    Gerd
  • On 21/01/2008, at 10:37 AM, Gerd Knops wrote:

    > This will only work if the underlying file system is case sensitive.
    > HFS just plays a case sensitive file system on TV, but in reality it
    > is not.

    HFS does have a case sensitive variant. By default, it comes case
    insensitive.

    - Chris
  • Have you tried FSRenameUnicode()?

    On Jan 20, 2008, at 10:36 AM, Simone Tessaro wrote:

    > this code doesn't work because cocoa seems to be case-sensitive and
    > this method is useless for my pourpose. So, i need a method like the
    > unix mv, in fact if i use the command mv foo.txt FOO.txt , everything
    > is allright.

    ---
    Sincerely,
    Rosyna Keller
    Technical Support/Carbon troll/Always needs a hug

    Unsanity: Unsane Tools for Insanely Great People

    It's either this, or imagining Phil Schiller in a thong.
  • 2008/1/21, Rosyna <rosyna...>:
    > Have you tried FSRenameUnicode()?

    HFS is insensitive. now it's for sure.
    At the end i've follow the tip of Clark Cox.
    i use the C function rename() int this way:
    rename([@"/foo.txt" fileSystemRepresentation], [@"/FOO.txt"
    fileSystemRepresentation]);

    For now seems the best way to rename a file with a insensitive FS. An
    maybe is fastest way.. maybe..

    Thanks to all for the precious suggests.

    S.
  • I'm not sure how that relates to using FSRenameUnicode().

    On Jan 20, 2008, at 6:03 PM, Simone Tessaro wrote:

    >> Have you tried FSRenameUnicode()?
    >
    > HFS is insensitive. now it's for sure.
    >

    ---
    Sincerely,
    Rosyna Keller
    Technical Support/Carbon troll/Always needs a hug

    Unsanity: Unsane Tools for Insanely Great People

    It's either this, or imagining Phil Schiller in a thong.
  • 2008/1/21, Rosyna <rosyna...>:
    > I'm not sure how that relates to using FSRenameUnicode().
    >
    nothing. for now i'm using renane() but i'm considering FSRenameUnicode().
    thanks

    S.
previous month january 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