implementing mv

Discussion in 'Python' started by Hong Jiang, Dec 24, 2003.

  1. Hong Jiang

    Hong Jiang Guest

    Hi,

    Is there an efficient way to implement the 'mv' command? I mean not by
    calling external commands.
    Moving a file can be done by first making a hard link then unlinking the
    original file. But I cannot figure out a good way to move a directory.
    Do I have to move all the files and subdirectories recursively?

    Thanks.
    Hong Jiang, Dec 24, 2003
    #1
    1. Advertising

  2. Hong Jiang wrote:

    > Is there an efficient way to implement the 'mv' command? I mean not by
    > calling external commands.


    Try shutil.move.

    Regards,
    Martin
    Martin v. Loewis, Dec 24, 2003
    #2
    1. Advertising

  3. Hong Jiang

    Jeff Epler Guest

    You should look at the 'shutil' module. It provides a move() function.

    $ pydoc shutil.move
    Help on function move in shutil:

    shutil.move = move(src, dst)
    Recursively move a file or directory to another location.

    If the destination is on our current filesystem, then simply use
    rename. Otherwise, copy src to the dst and then remove src.
    A lot more could be done here... A look at a mv.c shows a lot of
    the issues this implementation glosses over.
    (I assume mv.c is the source for the unix "/bin/mv" utility, available
    in multiple incarnations)

    Jeff
    Jeff Epler, Dec 24, 2003
    #3
  4. "Martin v. Loewis" <> wrote in message news:<bsblnd$ctm$02$-online.com>...
    > Hong Jiang wrote:
    >
    > > Is there an efficient way to implement the 'mv' command? I mean not by
    > > calling external commands.

    >
    > Try shutil.move.


    'Sometimes' os.rename can do moves too, however for your purposes
    shutil.move sounds better suited.


    David.
    David M. Wilson, Dec 24, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gomathi

    Implementing Interface

    Gomathi, Nov 17, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    553
    S.M. Altaf [MVP]
    Nov 17, 2005
  2. Eqbal Z
    Replies:
    3
    Views:
    5,085
    Eqbal
    Nov 16, 2003
  3. Dev

    Implementing E1 - E3

    Dev, Sep 9, 2004, in forum: VHDL
    Replies:
    1
    Views:
    727
    Allan Herriman
    Sep 9, 2004
  4. Johnsy Joseph
    Replies:
    2
    Views:
    1,094
    Brian Drummond
    Oct 29, 2004
  5. Riccardo Fregonese

    Need help implementing a proj on SPARTAN3

    Riccardo Fregonese, Dec 2, 2004, in forum: VHDL
    Replies:
    2
    Views:
    712
    Thomas Gebauer
    Jan 3, 2005
Loading...

Share This Page