CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    rename_file vs move_file

    I am writing a little OS agnostic library for my team for manipulating files.

    One such function is used to move/rename files (only files, not dirs). I got into a little argument with a colleague about naming: "rename" or "move"?

    "move" makes more sense, but the c api calls it rename.

    Is there any historic (or actual) difference between a "rename" and a "move" we could base ourselves on? Or is this purely an Apples vs Oranges?
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: rename_file vs move_file

    If you think of it in terms of renaming/moving a file, then whether "rename" or "move" makes more sense depends on whether the file will be in a different directory.

    If you think of it in terms of changing a file path, than "rename" makes more sense than "move".
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: rename_file vs move_file

    Another difference could be if overwriting another file with the same path as the destination is allowed. I don't know how this works on other platforms, but on Windows you cannot overwrite when using rename, but you can overwrite with move.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: rename_file vs move_file

    Another implementation difference is that rename usually can't change the device a file is on, but move can.

  5. #5
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: rename_file vs move_file

    Hum...

    Move it is then!

    Thanks
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  6. #6
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: rename_file vs move_file

    Instead of writing your own code, wouldn't the boost::filesystem do the trick?

  7. #7
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: rename_file vs move_file

    I wish, but this current project has the following restraints:
    1) No templates due to compiler limitations.
    2) No non in-house code.
    EDIT: 3) No exceptions.


    It's basically "C with classes here".

    That said, I'm not completly re-writing the wheel, my interface is mostly a convenience wrapper to a lower level API.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured