why doesn't is work?a script to backup a directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • obeeker@gmail.com

    #1

    why doesn't is work?a script to backup a directory

    """there is threee directories,one of these is used for the base
    directory,decid ed by the user, default is d0"""

    import shutil


    #the three directories
    d0='D:/Program Files/eb/mb/S'
    d1='O:/eb/mb/S'
    d2='P:/S/eb/mb/S'

    #to backup
    def update(base):
    l=[d0,d1,d2]
    l.remove(base)

    for i in l:
    shutil.rmtree(i )

    for i in l:
    shutil.copytree (base,i)

    #use the base directory to invoke the update() func
    def updateNow(base) :
    try:
    if base=='d1':
    update(d1)
    elif base=='d2':
    update(d2)
    else:
    update(d0)

    except:
    print "sth is wrong"
    else:
    print "OK!"

    #promt user which is the base
    if __name__ == '__main__':
    print 'd0=',d0
    print 'd1=',d1
    print 'd2=',d2
    base=raw_input( "your base/standard directory is d0 d1 or d2 ?\n")
    print base
    updateNow(base)

    raw_input('pres s Return>')

  • Steven D'Aprano

    #2
    Re: why doesn't is work?a script to backup a directory

    On Fri, 31 Mar 2006 18:37:11 -0800, obeeker wrote:
    [color=blue]
    > """there is threee directories,one of these is used for the base
    > directory,decid ed by the user, default is d0"""[/color]

    [snip code]

    It doesn't work? Have you tried running it to see what it does? When you
    do, please post a description of what it does, including any exception
    tracebacks, and just as importantly, what you expect it to do.


    --
    Steven.

    Comment

    • obeeker@gmail.com

      #3
      Re: why doesn't is work?a script to backup a directory

      thank you for your suggestion and apologize for my mistake.
      if i run it and answer the raw_input with "Enter" i get

      sth is wrong
      press Return>


      i comment the try-except and run it and answer the raw_input with
      "Enter"
      and get message following:


      Traceback (most recent call last):
      File "G:\9\Eb\update EbBb.py", line 41, in -toplevel-
      updateNow(base)
      File "G:\9\Eb\update EbBb.py", line 28, in updateNow
      update(d0)
      File "G:\9\Eb\update EbBb.py", line 16, in update
      shutil.rmtree(i )
      File "D:\Program Files\Python24\ lib\shutil.py", line 155, in rmtree
      onerror(os.list dir, path, sys.exc_info())
      File "D:\Program Files\Python24\ lib\shutil.py", line 153, in rmtree
      names = os.listdir(path )
      WindowsError: [Errno 3] : 'O:/eb/mb/SCIL/*.*'

      Comment

      • obeeker@gmail.com

        #4
        Re: why doesn't is work?a script to backup a directory

        please don't read the prevous post ,please read this one:


        thank you for your suggestion and apologize for my mistake.
        if i run it and answer the raw_input with "Enter" i get

        sth is wrong
        press Return>


        i comment the try-except and run it and answer the raw_input with
        "Enter"
        and get message following:


        Traceback (most recent call last):
        File "G:\9\Eb\update EbBb.py", line 41, in -toplevel-
        updateNow(base)
        File "G:\9\Eb\update EbBb.py", line 28, in updateNow
        update(d0)
        File "G:\9\Eb\update EbBb.py", line 16, in update
        shutil.rmtree(i )
        File "D:\Program Files\Python24\ lib\shutil.py", line 155, in rmtree
        onerror(os.list dir, path, sys.exc_info())
        File "D:\Program Files\Python24\ lib\shutil.py", line 153, in rmtree
        names = os.listdir(path )
        WindowsError: [Errno 3] : 'O:/eb/mb/S/*.*'

        Comment

        • Fredrik Lundh

          #5
          Re: why doesn't is work?a script to backup a directory

          obeeker@gmail.c om wrote:
          [color=blue]
          > please don't read the prevous post ,please read this one:
          >
          > thank you for your suggestion and apologize for my mistake.
          > if i run it and answer the raw_input with "Enter" i get
          >
          > sth is wrong
          > press Return>
          >
          > i comment the try-except and run it and answer the raw_input with
          > "Enter"
          > and get message following:
          >
          >
          > Traceback (most recent call last):
          > File "G:\9\Eb\update EbBb.py", line 41, in -toplevel-
          > updateNow(base)
          > File "G:\9\Eb\update EbBb.py", line 28, in updateNow
          > update(d0)
          > File "G:\9\Eb\update EbBb.py", line 16, in update
          > shutil.rmtree(i )
          > File "D:\Program Files\Python24\ lib\shutil.py", line 155, in rmtree
          > onerror(os.list dir, path, sys.exc_info())
          > File "D:\Program Files\Python24\ lib\shutil.py", line 153, in rmtree
          > names = os.listdir(path )
          > WindowsError: [Errno 3] : 'O:/eb/mb/S/*.*'[/color]

          shutil.rmtree() expects a directory name, not a file pattern. if you leave
          out the "*.*" part at the end, it should do what you want.

          (assuming you want to remove the eb/mb/S directory, that is)

          </F>



          Comment

          • obeeker@gmail.com

            #6
            Re: why doesn't is work?a script to backup a directory

            i am very sorry .
            the erroer was from my Portable Hard Disk
            because its disk sign has changed from "o" to "h" ,from "p" to "i"
            i'm very sorry

            Comment

            • Fredrik Lundh

              #7
              Re: why doesn't is work?a script to backup a directory

              I wrote:
              [color=blue][color=green]
              > > WindowsError: [Errno 3] : 'O:/eb/mb/S/*.*'[/color]
              >
              > shutil.rmtree() expects a directory name, not a file pattern. if you leave
              > out the "*.*" part at the end, it should do what you want.[/color]

              postscript: typically enough, I stumbled upon the same error message myself,
              a day later. looks like it's Windows that adds the "*.*" thing to the path, all
              by itself.

              however, on my machine, I get a bit more information:

              WindowsError: [Errno 3] The system cannot find the path specified:
              'directory/*.*'

              </F>



              Comment

              Working...