shutils.move lose files !

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

    shutils.move lose files !

    hello,

    here is a behavior that i discover by error :

    in the following example directory 'stupid' is lost such as eventual
    files and directory contained in it (for example 'atest.txt') while i
    would have prefer to be warned or at least nothing to happen.

    is it a bug ?

    ----------
    Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]
    on win32
    Type "copyright" , "credits" or "license()" for more information.

    *************** *************** *************** *************** ****
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface. This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    *************** *************** *************** *************** ****

    IDLE 1.0.2[color=blue][color=green][color=darkred]
    >>> import os
    >>> os.mkdir('c:/stupid')
    >>> open('c:/stupid/atest.txt', 'w').write('a file')
    >>> os.listdir('c:/stupid')[/color][/color][/color]
    ['atest.txt'][color=blue][color=green][color=darkred]
    >>> import shutil
    >>> shutil.move('c:/stupid', 'c:/stupid/donotexist')
    >>> os.listdir('c:/stupid')[/color][/color][/color]

    Traceback (most recent call last):
    File "<pyshell#2 2>", line 1, in -toplevel-
    os.listdir('c:/stupid')
    WindowsError: [Errno 3] Le chemin d'accès spécifié est introuvable:
    'c:/stupid/*.*'[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]
  • Jeff Epler

    #2
    Re: shutils.move lose files !

    The same happens on Linux:
    $ mkdir a; python2.3 -c 'import shutil; shutil.move("a" , "a/c")'
    $ ls -l a
    ls: a: No such file or directory

    Unix mv has a test that prevents this:
    $ mkdir a; mv a a/c
    mv: cannot move `a' to a subdirectory of itself, `a/c'

    I've created a sourceforge bug report about this. Visit here:


    Jeff

    Comment

    • Nicola Mingotti

      #3
      Re: shutils.move lose files !

      On Thu, 18 Mar 2004 05:27:10 -0800, Shagshag wrote:

      I get the same results under Linux .
      [color=blue]
      > is it a bug ?[/color]

      If it'isnt it looks like one a lot ;)

      -----
      Doing the equivalent in bash i get :
      $> mv tmp-dir/ tmp-dir/tmp-dir
      mv: cannot move `tmp-dir/' to a subdirectory of itself, `tmp-dir/tmp-dir'

      Leaning me more toward the bug hypothesis :)
      -----

      bye .





      Comment

      • Miki Tebeka

        #4
        Re: shutils.move lose files !

        Hello Shagshag,[color=blue][color=green][color=darkred]
        >>>>import os
        >>>>os.mkdir('c :/stupid')
        >>>>open('c:/stupid/atest.txt', 'w').write('a file')
        >>>>os.listdir( 'c:/stupid')[/color][/color]
        >
        > ['atest.txt']
        >[color=green][color=darkred]
        >>>>import shutil
        >>>>shutil.move ('c:/stupid', 'c:/stupid/donotexist')
        >>>>os.listdir( 'c:/stupid')[/color][/color]
        >
        >
        > Traceback (most recent call last):
        > File "<pyshell#2 2>", line 1, in -toplevel-
        > os.listdir('c:/stupid')
        > WindowsError: [Errno 3] Le chemin d'accès spécifié est introuvable:
        > 'c:/stupid/*.*'[color=green][color=darkred]
        >>> from os import mkdir, listdir
        >>> from shutil import move
        >>> mkdir("c:/temp/xxx")
        >>> open("c:/temp/xxx/moo", "w").write("moo ")
        >>> move("c:/temp/xxx/moo", "c:/temp/xxx/goo")
        >>> listdir("c:/temp/xxx")[/color][/color][/color]
        ['goo'][color=blue][color=green][color=darkred]
        >>>[/color][/color][/color]

        This is on win2k
        Miki

        Comment

        • Sibylle Koczian

          #5
          Re: shutils.move lose files !

          Miki Tebeka schrieb:
          [color=blue]
          > Hello Shagshag,
          >[color=green][color=darkred]
          >>>>> import os
          >>>>> os.mkdir('c:/stupid')
          >>>>> open('c:/stupid/atest.txt', 'w').write('a file')
          >>>>> os.listdir('c:/stupid')[/color]
          >>
          >>
          >> ['atest.txt']
          >>[color=darkred]
          >>>>> import shutil
          >>>>> shutil.move('c:/stupid', 'c:/stupid/donotexist')
          >>>>> os.listdir('c:/stupid')[/color]
          >>
          >>
          >>
          >> Traceback (most recent call last):
          >> File "<pyshell#2 2>", line 1, in -toplevel-
          >> os.listdir('c:/stupid')
          >> WindowsError: [Errno 3] Le chemin d'accès spécifié est introuvable:
          >> 'c:/stupid/*.*'[/color]
          >[color=green][color=darkred]
          > >>> from os import mkdir, listdir
          > >>> from shutil import move
          > >>> mkdir("c:/temp/xxx")
          > >>> open("c:/temp/xxx/moo", "w").write("moo ")
          > >>> move("c:/temp/xxx/moo", "c:/temp/xxx/goo")
          > >>> listdir("c:/temp/xxx")[/color][/color]
          > ['goo'][color=green][color=darkred]
          > >>>[/color][/color]
          >
          > This is on win2k
          > Miki[/color]

          But it's not the same thing: you are renaming a file, leaving it in its
          original directory. The original poster tried to move the directory into
          a subdirectory of itself.

          --
          Dr. Sibylle Koczian
          Universitaetsbi bliothek, Abt. Naturwiss.
          D-86135 Augsburg

          Tel.: (0821) 598-2400, Fax : (0821) 598-2410
          e-mail : Sibylle.Koczian @Bibliothek.Uni-Augsburg.DE

          Comment

          Working...