2012-05-30 6 views
-1

특정 시간이 경과 한 후 특정 폴더에서 파일을 삭제하는 프로그램에서 작업하고 있으며 정규 표현식이나 확장자를 사용하여 일치시킬 수 있습니다. 파일() 지금이 기록되는 방식배열이 비어있는 경우 유효성을 검사하는 방법

files(0) = Nothing 
files(1) = Nothing 
files(2) = Nothing 
ect.... 

을 할 수있는 곳 난

Else 
          log(1) = data(1) 
          log(3) = "Array field empty" 
          InsertLog(log) 

를 배치 할 수있는 문제로 실행하고있어 file(i) = Nothing가 보유 프로그램은 많은 로그 파일을 것입니다. 이것은 중복 된 데이터베이스 레코드를 만들 것이고 원하지 않습니다. ALL files(i) = Nothing을 입력하고 데이터베이스에 삽입 할 코드를 입력하는 방법이 있습니까?

  'If log(3) is successful that means no files were old enough or deleted successfully 
      If log(3) = "Success" And IsArray(files) Then 
       For Each file In files 
        If Not file.IsNullOrEmpty(file) Then 
         'If files is actually something insert into the log 
         log(1) = file 
         InsertLog(log) 
        'could place else here 
        End If 
       Next 
       files = Nothing 
      Else 
       'If no files or error in directory perform this 
       log(1) = data(1) 
       InsertLog(log) 
      End If 
+1

당신은 [File.GetLastWriteTime]에서 볼 수 없습니다 (http://msdn.microsoft.com/en-us/library/system.io.file.getlastwritetime.aspx)? – billinkc

답변

0

파일이 실제로 존재하는 경우 계산할 카운터를 추가 했으므로 간단한 해결책입니다.

  If log(3) = "Success" And IsArray(files) Then 
       j = 0 
       For Each file In files 
        If Not file.IsNullOrEmpty(file) Then 
         log(1) = file 
         InsertLog(log) 
         j += 1 
        End If 
       Next 
       If j = 0 Then 
        log(3) = "Files not old enough" 
        InsertLog(log) 
       End If 
       files = Nothing 
      Else 
       log(1) = data(1) 
       InsertLog(log) 
      End If 
0

소리가 너무 복잡해 보입니다. 파일이

  • 을 만들 때

    1. 데이터베이스에 타임 스탬프를 생성 주기적으로 일어나 아무것도 일을 얻을 때,
    2. 때때로 삭제

    을 필요로 아무것도 삭제 삭제해야하는 경우 확인 너무 복잡해서 공격 계획을 다시 생각할 때입니다.

  • 0
    Public Function AllArrayElementsAreNull(arr() As Object) As Boolean 
        Dim FoundNonNullItem As Boolean = False 
        For Each item As Object In Arr 
         If item IsNot Nothing Then 
          FoundNonNullItem = True 
          Exit For 
         End If 
        Next 
        Return Not FoundNonNullItem 
    End Function 
    
    관련 문제