moving multiple directories

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DataSmash

    #1

    moving multiple directories

    Hi,
    I need to organize thousands of directories full of files.
    I want to move these directories into other subdirectories.
    For example, all the directories that start with 01, move to
    a directory named "one", all directories that start with 02, move
    to a directory name "two", and so on....

    I can't seem to find any easy way to do this.
    Looks like shutil.move only lets you move if the subdirectory DOES
    NOT exist, so after the first directory moves, the script blows up on
    the second move.
    I guess you could use shutil.copy or shutil.copytree but then you have
    to
    delete as well. Much longer process when you have hundreds of
    gigabytes of data.

    Thanks for your help!
    R.D.

  • Larry Bates

    #2
    Re: moving multiple directories

    DataSmash wrote:
    Hi,
    I need to organize thousands of directories full of files.
    I want to move these directories into other subdirectories.
    For example, all the directories that start with 01, move to
    a directory named "one", all directories that start with 02, move
    to a directory name "two", and so on....
    >
    I can't seem to find any easy way to do this.
    Looks like shutil.move only lets you move if the subdirectory DOES
    NOT exist, so after the first directory moves, the script blows up on
    the second move.
    I guess you could use shutil.copy or shutil.copytree but then you have
    to
    delete as well. Much longer process when you have hundreds of
    gigabytes of data.
    >
    Thanks for your help!
    R.D.
    >
    Use win32.moveFile method instead. This links directly to the Windows
    MoveFile method that just moves the directory entries around.

    From Win32 Documentation:

    win32api.MoveFi le
    MoveFile(srcNam e, destName)

    Renames a file, or a directory (including its children).

    Parameters

    srcName : string

    The name of the source file.

    destName : string

    The name of the destination file.

    Comments
    This method can not move files across volumes.

    -Larry

    Comment

    • DataSmash

      #3
      Re: moving multiple directories

      Thanks Larry, I'll give that a try...
      R.D.


      >
      Use win32.moveFile method instead. This links directly to the Windows
      MoveFile method that just moves the directory entries around.
      >
      From Win32 Documentation:
      >
      win32api.MoveFi le
      MoveFile(srcNam e, destName)
      >
      Renames a file, or a directory (including its children).
      >
      Parameters
      >
      srcName : string
      >
      The name of the source file.
      >
      destName : string
      >
      The name of the destination file.
      >
      Comments
      This method can not move files across volumes.
      >
      -Larry

      Comment

      • ici

        #4
        Re: moving multiple directories

        On Apr 16, 9:36 pm, Larry Bates <larry.ba...@we bsafe.comwrote:
        DataSmash wrote:
        Hi,
        I need to organize thousands of directories full of files.
        I want to move these directories into other subdirectories.
        For example, all the directories that start with 01, move to
        a directory named "one", all directories that start with 02, move
        to a directory name "two", and so on....
        >
        I can't seem to find any easy way to do this.
        Looks like shutil.move only lets you move if the subdirectory DOES
        NOT exist, so after the first directory moves, the script blows up on
        the second move.
        I guess you could use shutil.copy or shutil.copytree but then you have
        to
        delete as well. Much longer process when you have hundreds of
        gigabytes of data.
        >
        Thanks for your help!
        R.D.
        >
        Use win32.moveFile method instead. This links directly to the Windows
        MoveFile method that just moves the directory entries around.
        >
        From Win32 Documentation:
        >
        win32api.MoveFi le
        MoveFile(srcNam e, destName)
        >
        Renames a file, or a directory (including its children).
        >
        Parameters
        >
        srcName : string
        >
        The name of the source file.
        >
        destName : string
        >
        The name of the destination file.
        >
        Comments
        This method can not move files across volumes.
        >
        -Larry
        Instead win32api, use "native" shutil module

        import shutil
        shutil.move(src ,dest)

        Recursively move a file or directory to another location.

        Comment

        Working...