Дмитрий Максимов (dmitry_maximov) wrote,
Дмитрий Максимов
dmitry_maximov

А я программу написал!

Imports System
Imports System.IO
Module Module1
    Sub Main()
        Dim S As String

        For Each S In My.Application.CommandLineArgs
            ProcessDirectory(S)
        Next

        '        ProcessDirectory("C:\Test")


    End Sub
    Sub ProcessDirectory(ByVal Path As String)
        Dim ModifyTime, LatestTime, ModifyTime2 As DateTime
        Dim DirNameColl, FileNameColl As String()
        Dim DirName, FileName As String
        Dim NoDirs, NoFiles As Boolean

        Debug.WriteLine(Path)
        ModifyTime = Directory.GetLastWriteTime(Path)
        Debug.WriteLine(ModifyTime)

        LatestTime = DateTime.MinValue

        DirNameColl = Directory.GetDirectories(Path)
        If DirNameColl.Length > 0 Then
            For Each DirName In DirNameColl
                ProcessDirectory(DirName)
                ModifyTime2 = Directory.GetLastWriteTime(DirName)
                If DateTime.Compare(LatestTime, ModifyTime2) < 0 Then
                    LatestTime = ModifyTime2
                End If
            Next
        Else
            NoDirs = True
        End If

        FileNameColl = Directory.GetFiles(Path)
        If FileNameColl.Length > 0 Then
            For Each FileName In FileNameColl
                Debug.WriteLine(FileName)
                ModifyTime2 = Directory.GetLastWriteTime(FileName)
                If DateTime.Compare(LatestTime, ModifyTime2) < 0 Then
                    LatestTime = ModifyTime2
                End If
            Next
        Else
            NoFiles = True
        End If


        If NoDirs And NoFiles Then
            Console.WriteLine(Path & ": Empty")
        Else
            If DateTime.Compare(LatestTime, ModifyTime) <> 0 Then
                Console.WriteLine(Path & ": " & ModifyTime & " --> " & LatestTime)
                Debug.WriteLine(Path & ": " & ModifyTime & " --> " & LatestTime)
                Try
                    Directory.SetLastWriteTime(Path, LatestTime)
                Catch ex As Exception
                    Console.WriteLine("!!! Error setting time " & ex.Message)
                    Debug.WriteLine("╬°шсър!")
                End Try
            Else
                Debug.WriteLine(Path & ": " & "Not modified")
            End If
        End If
    End Sub

End Module

Tags: работа
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments