Ejemplo n.º 1
0
def CopyFileToCe(src_name, dest_name, progress=None):
    sh = win32file.CreateFile(
        src_name,
        win32con.GENERIC_READ,
        0,
        None,
        win32con.OPEN_EXISTING,
        0,
        None)
    bytes = 0
    try:
        dh = wincerapi.CeCreateFile(
            dest_name,
            win32con.GENERIC_WRITE,
            0,
            None,
            win32con.OPEN_ALWAYS,
            0,
            None)
        try:
            while True:
                hr, data = win32file.ReadFile(sh, 2048)
                if not data:
                    break
                wincerapi.CeWriteFile(dh, data)
                bytes = bytes + len(data)
                if progress is not None:
                    progress(bytes)
        finally:
            pass
            dh.Close()
    finally:
        sh.Close()
    return bytes
Ejemplo n.º 2
0
def DemoCopyFile():
    # Create a file on the device, and write a string.
    cefile = wincerapi.CeCreateFile(
        "TestPython",
        win32con.GENERIC_WRITE,
        0,
        None,
        win32con.OPEN_ALWAYS,
        0,
        None)
    wincerapi.CeWriteFile(cefile, "Hello from Python")
    cefile.Close()
    # reopen the file and check the data.
    cefile = wincerapi.CeCreateFile(
        "TestPython",
        win32con.GENERIC_READ,
        0,
        None,
        win32con.OPEN_EXISTING,
        0,
        None)
    if wincerapi.CeReadFile(cefile, 100) != "Hello from Python":
        print("Couldnt read the data from the device!")
    cefile.Close()
    # Delete the test file
    wincerapi.CeDeleteFile("TestPython")
    print("Created, wrote to, read from and deleted a test file!")