Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any simple way to put file names into the text file?
Message
General information
Forum:
Windows
Category:
Computing in general
Miscellaneous
Thread ID:
01285227
Message ID:
01299037
Views:
12
>try:
>fileInfo = New IO.FileInfo(files(i))

I found couple of things so far. Extension includes '.'

Anyway, here is my current code, the only minor thing which is missing is to remove whole directory and only show the relevant path.

I didn't add Wait window, don't want to spend more time than needed on this little thing.
Imports System.IO
Imports System.Text


Public Class Form1
    Dim TargetFileText As New StringBuilder 'declare it outside any function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Dim files() As String
        'Dim fileList As New System.Text.StringBuilder
        'Dim myDate As DateTime = Me.dtpModified.Value
        'Dim fileInfo As IO.FileInfo
        GetFiles(Me.txtDirectory.Text, Me.dtpModified.Value, ".ASPX")
        'files = IO.Directory.GetFiles(Me.txtDirectory.Text, "*.*")

        'For i As Integer = 0 To files.Length - 1
        '    fileInfo = New IO.FileInfo(files(1))
        '    If fileInfo.LastWriteTime > myDate And fileInfo.Extension.ToUpper() = ".ASPX" Then
        '        fileList.Append(files(i))
        '        fileList.Append(Environment.NewLine)
        '    End If
        'Next

        Dim writer As New IO.StreamWriter(Me.txtOutput.Text)
        writer.Write(TargetFileText.ToString)
        writer.Close()
        MsgBox("The file with all latest changes is created")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' Show the FolderBrowserDialog.
        Dim result As DialogResult = FolderBrowserDialog1.ShowDialog()

        If (result = DialogResult.OK) Then
            Me.txtDirectory.Text = FolderBrowserDialog1.SelectedPath
        End If

    End Sub
    'THIS FUNCTION WILL RECUSRSIVELY FIND FILES IN PARTICULAR FOLDER
    Private Sub GetFiles(ByVal DirName As String, ByVal LastDate As Date, ByVal Ext As String)

        Dim d As DirectoryInfo = New DirectoryInfo(DirName)

        Dim f() As FileInfo = d.GetFiles()

        Dim Counter As Integer
        Counter = 0
        ' TargetFileText.Append(vbCrLf + "-------------------------------------------------" + vbCrLf)
        'TargetFileText.Append("Directory: " & d.FullName & vbCrLf)
        'TargetFileText.Append("Name" & vbTab & vbTab & "Bytes" & vbTab & "Last Modified" & vbCrLf)

        Dim fi As FileInfo

        For Each fi In f
            If fi.Extension.ToUpper = Ext And fi.LastWriteTime > LastDate Then
                Counter = Counter + 1
                If Counter = 1 Then
                    TargetFileText.Append("Directory: " & d.FullName)
                End If

                TargetFileText.Append(Counter.ToString & vbTab & fi.Name) ' & vbTab & fi.Length & vbTab & fi.LastWriteTime & vbCrLf)
            End If
        Next

        Dim innerFolders As DirectoryInfo

        For Each innerFolders In d.GetDirectories()
            GetFiles(innerFolders.FullName, LastDate, Ext)
        Next
    End Sub

End Class
UPDATE. Forgot to add a new line.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform