-1

私は、一定の時間が経過した後、特定のフォルダーからファイルを削除し、正規表現または拡張子で一致するプログラムに取り組んでいます。files() が

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
4

3 に答える 3

0

あなたはそれをあまりにも複雑にしているように聞こえます。

  1. ファイルが作成されたときにデータベースにタイムスタンプを作成する
  2. 定期的に起動して、何か削除する必要があるかどうかを確認します
  3. 削除が必要なものを削除する

状況が複雑になりすぎると、攻撃計画を再考するときが来ることがあります。

于 2012-05-30T19:26:44.367 に答える
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 
于 2012-05-30T19:27:37.337 に答える
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
于 2012-05-30T21:12:52.597 に答える