文件同步程序,Python和C写的DLL

 1 #coding:utf-8
 2 
 3 from ctypes import *
 4 from FileCopy import *
 5 
 6 def GetFilePathList(FilePath):
 7     dll = CDLL(r"F:\VSProject\FileFunction20190101Dll\Release\FileFunction20190101Dll.dll")
 8     Length = c_int(0)
 9     return dll.TraversFileInterface(FilePath)
10 
11 des = 'E:\Pictures'
12 src = 'J:\Video&Pictures'
13 
14 
15 #源路径文件列表获取
16 psrcchar = GetFilePathList(src)
17 szSrcBuffer = c_char_p(psrcchar)
18 SrcFilePath = szSrcBuffer.value
19 SrcFilePathList = SrcFilePath.split('\r\n')
20 
21 #目标文件列表获取
22 pdeschar = GetFilePathList(des)
23 szDesBuffer = c_char_p(pdeschar)
24 DesFilePath = szDesBuffer.value
25 DesFilePathList = DesFilePath.split('\r\n')
26 
27 #生成目标路径比对集合
28 DesFileSet = set()
29 for FilePath in DesFilePathList:
30     #print FilePath.split('\\')[-1]
31     DesFileSet.add(FilePath.split('\\')[-1])
32 
33 NewSrcFileList = []
34 #根据目标路径内容剔除已存在文件
35 for FilePath in SrcFilePathList:
36     #print FilePath.split('\\')[-1]
37     if FilePath.split('\\')[-1] not in DesFileSet:
38         NewSrcFileList.append(FilePath)
39 
40 #根据目的地址路径对源文件列表进行改造替换,生成拷贝目的地址
41 DesCopyList = []
42 for FilePath in NewSrcFileList:
43     CopyPath = FilePath.replace(src, des)
44     CopyPath = CopyPath[0:CopyPath.rfind('\\')+1]
45     CopyFromSrcToDes (FilePath, CopyPath)
46     #DesCopyList.append(CopyPath)
47 
48 print len(NewSrcFileList)
49 print len(DesCopyList)
50 #dll.PrintHex(filedata, len(filedata))

FileCopy文件

 1 import os
 2 
 3 def CopyFileByList():
 4     return
 5 
 6 def CopyFromSrcToDes(src, des):
 7     cmdname = 'xcopy ' + '\"' + src + '\"' + ' \"' + des + '\"'
 8     RunCmd(cmdname)
 9     return
10 
11 def RunCmd(cmd):
12     print cmd
13     ret = os.system(cmd)
14     return

 

转载于:https://www.cnblogs.com/matrix-r/p/10548835.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值