主题:[原创]疯狂的VFPER之删除目录(包括其所有下级文件及文件夹)
VFP的RD可以删除目录,但目录必须为空,如果目录下有子目录或是文件,子目录下还有子目录或是文件就比较麻烦,我自己写了一个函数,可以删除目录(包括其所有下级文件及文件夹)。
将以下代码存为DeleteTree.prg,在其它地方调用,如DeleteTree("C:\Windows"),哈哈,别乱来哦:)。
Lparameters tcDirectory
If !(Vartype(tcDirectory)="C" And Directory(tcDirectory))
Return .F.
Endif
Private lcDirectory,laDir,lnCount,i,lcFileName
lcDirectory = Addbs(tcDirectory)
Delete File (lcDirectory + "*.*")
lnCount = Adir(laDir,lcDirectory + "*.*","D",1)
If lnCount>=1
For i = 1 To lnCount
lcFileName = laDir(i,1)
If !lcFileName=="." And !lcFileName==".."
If "D" $ laDir(i,5)
DeleteTree(lcDirectory + lcFileName)
Endif
Endif
Endfor
Endif
Rd (lcDirectory)
将以下代码存为DeleteTree.prg,在其它地方调用,如DeleteTree("C:\Windows"),哈哈,别乱来哦:)。
Lparameters tcDirectory
If !(Vartype(tcDirectory)="C" And Directory(tcDirectory))
Return .F.
Endif
Private lcDirectory,laDir,lnCount,i,lcFileName
lcDirectory = Addbs(tcDirectory)
Delete File (lcDirectory + "*.*")
lnCount = Adir(laDir,lcDirectory + "*.*","D",1)
If lnCount>=1
For i = 1 To lnCount
lcFileName = laDir(i,1)
If !lcFileName=="." And !lcFileName==".."
If "D" $ laDir(i,5)
DeleteTree(lcDirectory + lcFileName)
Endif
Endif
Endfor
Endif
Rd (lcDirectory)