文件同步程序,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

 

posted @ 2019-03-17 20:57  Matrix_R  阅读(390)  评论(0编辑  收藏  举报