主题:[原创]疯狂的VFPER之XCopy
我自己写了一个拷贝文件夹(包括其所有下级文件及文件夹)的函数。
将以下代码存为XCopy.prg,在其它地方调用,如XCopy("C:\Windows","D:\Windows"),将C:\Windows及其下级COPY到D:\Windows。
Lparameters tcDirectory1,tcDirectory2
If !(Vartype(tcDirectory1)="C" And Directory(tcDirectory1) And Vartype(tcDirectory2)="C" And !Empty(tcDirectory2))
Return .F.
Endif
Private lcDirectory1,lcDirectory2,laDir,lnCount,i,lcFileName,lcFile1,lcFile2
lcDirectory1 = Addbs(tcDirectory1)
lcDirectory2 = Addbs(tcDirectory2)
If !Directory(lcDirectory2)
Md (lcDirectory2)
Endif
lnCount = Adir(laDir,lcDirectory1 + "*.*","D",1)
If lnCount>=1
For i = 1 To lnCount
lcFileName = laDir(i,1)
If !lcFileName=="." And !lcFileName==".."
lcFile1 = lcDirectory1 + lcFileName
lcFile2 = lcDirectory2 + lcFileName
If "D" $ laDir(i,5)
XCopy(lcFile1,lcFile2)
Else
Copy File (lcFile1) To (lcFile2)
Endif
Endif
Endfor
Endif
将以下代码存为XCopy.prg,在其它地方调用,如XCopy("C:\Windows","D:\Windows"),将C:\Windows及其下级COPY到D:\Windows。
Lparameters tcDirectory1,tcDirectory2
If !(Vartype(tcDirectory1)="C" And Directory(tcDirectory1) And Vartype(tcDirectory2)="C" And !Empty(tcDirectory2))
Return .F.
Endif
Private lcDirectory1,lcDirectory2,laDir,lnCount,i,lcFileName,lcFile1,lcFile2
lcDirectory1 = Addbs(tcDirectory1)
lcDirectory2 = Addbs(tcDirectory2)
If !Directory(lcDirectory2)
Md (lcDirectory2)
Endif
lnCount = Adir(laDir,lcDirectory1 + "*.*","D",1)
If lnCount>=1
For i = 1 To lnCount
lcFileName = laDir(i,1)
If !lcFileName=="." And !lcFileName==".."
lcFile1 = lcDirectory1 + lcFileName
lcFile2 = lcDirectory2 + lcFileName
If "D" $ laDir(i,5)
XCopy(lcFile1,lcFile2)
Else
Copy File (lcFile1) To (lcFile2)
Endif
Endif
Endfor
Endif