Google Mobile Ads

Sunday, December 11, 2016

Belirli bir günden önceki dosyaları silme metodu.

Belirli bir günden önceki dosyaları silme metodu.

Aşağıdaki metod ile "folderPath" klasöründe beforeDayCount parametresinde belirtilen gün sayısından daha önce oluşturulmuş dosyalar silinir.


    Public Shared Sub DeleteFiles(folderPath As String, Optional beforeDayCount As Integer = 30)
        If (folderPath.Trim() <> "" And beforeDayCount <> 0) AndAlso System.IO.Directory.Exists(folderPath) Then
            Dim folderInfo As New System.IO.DirectoryInfo(folderPath)
            Dim fileList As System.IO.FileInfo() = folderInfo.GetFiles()

            For Each fi As System.IO.FileInfo In fileList
                If fi.LastWriteTime <= DateAdd(DateInterval.Day, IIf(beforeDayCount < 0, beforeDayCount, -1 * beforeDayCount), Date.Now) Then
                    Try
                        System.IO.File.Delete(fi.FullName)
                    Catch ex As Exception

                    End Try
                End If
            Next
        End If
    End Sub

LinkWithin

Related Posts Plugin for WordPress, Blogger...