vinicius.ferreira Posted April 2, 2014 Report Share Posted April 2, 2014 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 More sharing options...
nelsonr Posted April 2, 2014 Report Share Posted April 2, 2014 Será algo do tipo foreach (String file in openFileDialog1.FileNames) http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.multiselect%28v=vs.110%29.aspx Link to comment Share on other sites More sharing options...
vinicius.ferreira Posted April 3, 2014 Author Report Share Posted April 3, 2014 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 More sharing options...
vinicius.ferreira Posted May 5, 2014 Author Report Share Posted May 5, 2014 Resolvido Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now