You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
4.1 KiB
99 lines
4.1 KiB
Imports System.IO
|
|
Module Module1
|
|
|
|
#Region "Deklarationen"
|
|
|
|
Dim db As New clsDB
|
|
Dim conn As New DB_Connection
|
|
Dim JobReturn As Integer = 0
|
|
Dim Counter_Correct As Integer = 0
|
|
|
|
#End Region
|
|
|
|
Sub Main()
|
|
write_log("Start EDKB20 - Delete EDKB09-Dateien und Verzeichnisse")
|
|
write_log("Verzeichnis: " + My.Settings.Path_to_EDKB09)
|
|
write_log("Daten älter als " + My.Settings.aelter_als.ToString + " Tage")
|
|
Get_Files()
|
|
|
|
db.Sendmail(My.Settings.MailEmpfaenger, JobReturn, Counter_Correct)
|
|
write_log("EDKB20 Ende")
|
|
write_log("************")
|
|
write_log("")
|
|
write_log("")
|
|
|
|
End Sub
|
|
|
|
Sub Get_Files()
|
|
Dim files() As String = IO.Directory.GetFiles(My.Settings.Path_to_EDKB09)
|
|
Dim debugmode As Boolean = UCase(My.Settings.DebugMode) = "TRUE"
|
|
For Each ifile As String In files
|
|
Dim ext As String = System.IO.Path.GetExtension(ifile)
|
|
If UCase(ext) = ".XML" Then
|
|
Dim fileCreatedDate As DateTime = File.GetCreationTime(ifile)
|
|
Dim FileModifeidDate As DateTime = File.GetLastWriteTime(ifile)
|
|
Dim DoFileAccess As Boolean = False
|
|
If (UCase(My.Settings.Use_Create_Date) = "TRUE" And fileCreatedDate < DateAdd(DateInterval.Day, My.Settings.aelter_als * -1, Now)) Then
|
|
DoFileAccess = True
|
|
End If
|
|
If (UCase(My.Settings.Use_Modified_Date) = "TRUE" And FileModifeidDate < DateAdd(DateInterval.Day, My.Settings.aelter_als * -1, Now)) Then
|
|
DoFileAccess = True
|
|
End If
|
|
If DoFileAccess = True Then
|
|
If all_documents_in_edoka(ifile) Then
|
|
Try
|
|
If Not debugmode Then System.IO.File.Delete(ifile)
|
|
write_log("Datei gelöscht:" + ifile)
|
|
Catch ex As Exception
|
|
write_log("Datei nicht gelöscht:" + ifile + " " + ex.Message)
|
|
End Try
|
|
Dim fn As String = System.IO.Path.GetFileName(ifile)
|
|
Dim words As String() = fn.Split("_")
|
|
|
|
Dim FileLocation As DirectoryInfo = New DirectoryInfo(My.Settings.Path_to_EDKB09)
|
|
Dim fi As FileInfo() = FileLocation.GetFiles(words(0).ToString + "_*.*")
|
|
|
|
For Each f In fi
|
|
Try
|
|
If Not debugmode Then System.IO.File.Delete(f.FullName)
|
|
write_log("Datei gelöscht:" + f.FullName)
|
|
Catch ex As Exception
|
|
write_log("Datei nicht gelöscht:" + f.FullName + " " + ex.Message)
|
|
End Try
|
|
Next
|
|
Try
|
|
If Not debugmode Then System.IO.Directory.Delete(My.Settings.Path_to_EDKB09 + words(0), True)
|
|
write_log("Directory gelöscht: " + My.Settings.Path_to_EDKB09 + words(0))
|
|
Catch ex As Exception
|
|
write_log("Directory nicht gelöscht: " + My.Settings.Path_to_EDKB09 + words(0))
|
|
|
|
End Try
|
|
Else
|
|
write_log("Nicht alle Dokumente in EDOKA - keine Löschung durchgeführt: " + ifile)
|
|
End If
|
|
|
|
End If
|
|
End If
|
|
|
|
Next
|
|
End Sub
|
|
|
|
Function all_documents_in_edoka(ByVal filename As String) As Boolean
|
|
Dim all_docs_exists As Boolean = True
|
|
Dim ds As New DataSet
|
|
ds.ReadXml(filename)
|
|
For Each r As DataRow In ds.Tables(0).Rows
|
|
If db.Check_File(r.Item("Dokumentid")) = False Then all_docs_exists = False
|
|
Next
|
|
Return all_docs_exists
|
|
End Function
|
|
|
|
Public Sub write_log(ByVal s As String)
|
|
If UCase(My.Settings.WriteLog) = "TRUE" Then
|
|
FileOpen(1, My.Settings.LogFile, OpenMode.Append)
|
|
WriteLine(1, Now.ToShortDateString + " : " + s)
|
|
FileClose(1)
|
|
End If
|
|
End Sub
|
|
End Module
|