#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Atlantic City, NJ
    Posts
    327
    Rep Power
    13

    Windows File Copy


    I'm writing a small script that will be placed on Windows client machines to upload all there days data to a remote server.

    After messing around with many text based progress bars I figured it would probably be better if the script just passed off the file copying to Windows. I can't figure out what I need to make this work. I want it so Windows file progress box pops up while the files are copying.

    I've been looking through win32 help stuff for a while now and nothing seems to work. Any help would be appreciated.

    Thanks.
    I'll learn this stuff someday.
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    I was researching an answer when I found this...
    http://www.codecomments.com/archive278-2004-5-195049.html
    I'd like to say this is my code but its not :

    python Code:
    #
    # Progress bar control example
    #
    # PyCProgressCtrl encapsulates the MFC CProgressCtrl class. To use it,
    # you:
    #
    # - Create the control with win32ui.CreateProgressCtrl()
    # - Create the control window with PyCProgressCtrl.CreateWindow()
    # - Initialize the range if you want it to be other than (0, 100) using
    # PyCProgressCtrl.SetRange()
    # - Either:
    # - Set the step size with PyCProgressCtrl.SetStep(), and
    # - Increment using PyCProgressCtrl.StepIt()
    # or:
    # - Set the amount completed using PyCProgressCtrl.SetPos()
    #
    # Example and progress bar code courtesy of KDL Technologies, Ltd., Hong
    #Kong SAR, China.
    #
     
    from pywin.mfc import dialog
    import win32ui
    import win32con
    import time
     
    def MakeDlgTemplate():
        style = (win32con.DS_MODALFRAME |
        win32con.WS_POPUP |
        win32con.WS_VISIBLE |
        win32con.WS_CAPTION |
        win32con.WS_SYSMENU |
        win32con.DS_SETFONT)
        cs = (win32con.WS_CHILD |
        win32con.WS_VISIBLE)
     
        w = 215
        h = 36
     
        dlg = [["Progress bar",   (0, 0, w, h),    style,    None,    (8, "MS Sans Serif")],    ]
        return dlg
     
    class TestDialog(dialog.Dialog):
     
        def OnInitDialog(self):
            rc = dialog.Dialog.OnInitDialog(self)
            self.pbar = win32ui.CreateProgressCtrl()
            self.pbar.CreateWindow (win32con.WS_CHILD | win32con.WS_VISIBLE, (10, 10, 310, 24), self, 1001)
            return rc
     
    def demo():
        d = TestDialog (MakeDlgTemplate())
        d.CreateWindow ()
        for i in xrange(100):
            d.pbar.SetPos(i)
            time.sleep(0.1)
     
        d.OnCancel()
     
    if __name__=='__main__':
        demo()


    I hope this helps.

    grim
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Atlantic City, NJ
    Posts
    327
    Rep Power
    13
    That would be fabulous to use except I'm not sure how I would implement that in a file copy. How would the progress bar know how far along the file copying is at?
    I'll learn this stuff someday.
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Well I guess its only useful if you want write your own copying scheme First off you need to know how big the file is that you want to copy. If you copy a file in chunks then as the chunk is written you just update the progress bar.

    Say the file is 24kbytes and you copy in 1k chunks then set the range of the progress bar to 24 self.pbar.SetRange(0,24) ,set the step size to self.pbar.SetStep(1) and then call self.pbar.StepIt() each time a chunk is copied.

    If you were copying a list of files then the each step might be a whole file.

    This would be great for ftplib but is going to be slow for basic system file copies.


    If you don't want to do this then you'll have to figure how to use the Windows Explorer copy facilities.

    grim
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Atlantic City, NJ
    Posts
    327
    Rep Power
    13
    Thanks for all your help Grim.

    I figured out how to do it via the explorer copy function.

    Code:
    from win32com.shell import shell, shellcon
    shell.SHFileOperation((0,shellcon.FO_COPY,'C:\\test1\\*','C:\\test2\\MyDocs\\',shellcon.FOF_ALLOWUNDO|shellcon.FOF_NOCONFIRMATION|shellcon.FOF_NOCONFIRMMKDIR))
    Honestly, I can't really explain what it does other then copy all the files from C:\test1 to C:\test2 and use explorer's file progress bar while doing it. The SHFileOperation has very strange syntax in my opinion. At least I got it to work though.

    Thanks again.
    I'll learn this stuff someday.

IMN logo majestic logo threadwatch logo seochat tools logo