I’m working on a program to delete files from a certain folder after they have aged a certain amount of time and either match via regex or extension. I’m running into an issue where files() could be
files(0) = Nothing
files(1) = Nothing
files(2) = Nothing
ect....
Right now the way it is written, I could place
Else
log(1) = data(1)
log(3) = "Array field empty"
InsertLog(log)
and the program would log as many files as file(i) = Nothing holds. This would create redundant database records and is not wanted. Is there a way to figure out if ALL files(i) = Nothing and then place code in there to insert into the database?
'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
I added a counter to count if a file actually exists, simple solution.