Jump to content

[Resolvido] Arquivo .TXT


Recommended Posts

Olá Pessoal!

Estou precisando desenvolver um software para tratar alguns erros de alguns .txt.

O tratamento do arquivo já consegui efetuar, para abrir utilizei o openFileDialog.

No caso tenho em torno de uns 2 mil arquivos para tratar.

Gostaria de saber como posso criar um loop que busca esses arquivos na pasta.

Obrigado!

Link to comment
Share on other sites

Imports System.IO
Public Class Form1
Private Sub btnConverter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConverter.Click
    If ((rbtAm8c.Checked = True) Or (rbtUsm.Checked = True)) Then
        Dim strRead As String
        Dim sr As New System.IO.StreamReader(filesListBox.Text)
        Dim qtdCaracter
        Dim contador As Integer
        Using arquivo As New System.IO.StreamWriter(filesListBox.Text & ".txt")
            Using erro As New System.IO.StreamWriter("ERRO - " & lblNomeArq.Text & ".txt")
                contador = 0
                strRead = sr.ReadLine
                While (strRead <> Nothing)
                    qtdCaracter = Len(strRead)
                    If (rbtAm8c.Checked = True) Then
                        If (qtdCaracter <= 417) Then
                            arquivo.WriteLine(strRead)
                        Else
                            erro.WriteLine(strRead)
                            contador += 1
                        End If
                    End If
                    If (rbtUsm.Checked = True) Then
                        If (qtdCaracter <= 112) Then
                            arquivo.WriteLine(strRead)
                        Else
                            erro.WriteLine(strRead)
                            contador += 1
                        End If
                    End If
                    strRead = sr.ReadLine
                End While
                MsgBox("Arquivo Gerado com Sucesso tivemos " & contador & " Erros")
            End Using
        End Using
    Else
        MsgBox("Preencha todos os Campos!")
    End If
End Sub
Private Sub browseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles browseButton.Click
    If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
        'Lista de arquivos na pasta.
        ListFiles(FolderBrowserDialog1.SelectedPath)
    End If

End Sub
Private Sub ListFiles(ByVal folderPath As String)
    filesListBox.Items.Clear()
    Dim fileNames = My.Computer.FileSystem.GetFiles(folderPath, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
    For Each fileName As String In fileNames
        filesListBox.Items.Add(fileName)
    Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    FolderBrowserDialog1.SelectedPath = My.Computer.FileSystem.CurrentDirectory
End Sub
End Class

Consegui abrir os arquivos(.txt) no ListBox, estou com dificuldade para manipular esses arquivos!

Uma delas e pegar somente o nome do arquivo e gerar outro tratado com o mesmo nome

falta um loop que percorre todos arquivos tratando

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.