2009-11-15 55 views
1

使用VB6爲什麼我的循環只刪除一個文件?

在一個文件夾,我有文件的n個,我想刪除一個0 KB文件

代碼

Dim filename5 As String 
filename5 = Dir$(txtsourcedatabasefile & "\*_*", vbDirectory) 
MsgBox filename5 
Do While filename5 <> "" 
    If FileLen(txtsourcedatabasefile & "\" & filename5) = 0 Then 
     Kill txtsourcedatabasefile & "\" & filename5 
    End If 
Loop 

txtsourcedatabasefile - 路徑

上面的代碼是隻刪除一個文件,其餘文件不刪除。將錯誤顯示爲未找到文件。

我的代碼有什麼問題?

需要VB6代碼幫助

回答

0

你有無需參數再次調用Dir函數。這是通過將Dir函數放入循環中完成的

Dim filename5 As String 
filename5 = Dir$(txtsourcedatabasefile & "\*_*", vbDirectory) 
MsgBox filename5 

Do While filename5 <> "" 
    If FileLen(txtsourcedatabasefile & "\" & filename5) = 0 Then 
     Kill txtsourcedatabasefile & "\" & filename5 
     filename5 = Dir 
    End If 
Loop 
相關問題