Documentos de Académico
Documentos de Profesional
Documentos de Cultura
En este tutorial se ofrece una introducción a los conceptos básicos de E/S de archivos en
Visual Basic. En él se describe cómo crear una pequeña aplicación que enumera y examina
archivos de texto en un directorio. Para cada archivo de texto seleccionado, la aplicación
proporciona atributos de archivo y la primera línea de contenido. Existe una opción para
escribir información en un archivo de registro.
En este tutorial se usan los miembros del elemento My.Computer.FileSystem Object , que
están disponibles en Visual Basic. Vea FileSystem para obtener más información. Al final
Descargar PDF
del tutorial, se incluye un ejemplo equivalente que usa clases del espacio de nombres
System.IO.
7 Nota
Text Examinar
VB = Copiar
VB = Copiar
El método GetFiles recupera entonces una colección de cadenas, una para cada
archivo del directorio. El método GetFiles acepta un argumento de patrón de
búsqueda para recuperar los archivos que coinciden con un patrón determinado. En
este ejemplo, se devuelven solo los archivos que tengan la extensión .txt.
VB = Copiar
' Obtain the file path from the list box selection.
Dim filePath = filesListBox.SelectedItem.ToString
' Verify that the file was not removed since the
' Browse button was clicked.
If My.Computer.FileSystem.FileExists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If
VB = Copiar
Return sb.ToString
End Function
El código usa el método GetFileInfo para obtener los parámetros del archivo. Los
parámetros del archivo se agregan a StringBuilder.
4. Ejecute la aplicación. Haga clic en Examinar y busque una carpeta que contenga
archivos .txt. Haga clic en Aceptar.
VB = Copiar
VB = Copiar
' Set the default directory of the folder browser to the current directory.
FolderBrowserDialog1.SelectedPath = My.Computer.FileSystem.CurrentDirectory
VB = Copiar
examineButton.Enabled = anySelected
saveCheckBox.Enabled = anySelected
End Sub
VB = Copiar
SetEnabled()
End Sub
' Obtain the file path from the list box selection.
Dim filePath = filesListBox.SelectedItem.ToString
' Verify that the file was not removed since the
' Browse button was clicked.
If My.Computer.FileSystem.FileExists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If
Return sb.ToString
End Function
examineButton.Enabled = anySelected
saveCheckBox.Enabled = anySelected
End Sub
VB = Copiar
SetEnabled()
End Sub
' Obtain the file path from the list box selection.
Dim filePath = filesListBox.SelectedItem.ToString
' Verify that the file was not removed since the
' Browse button was clicked.
If System.IO.File.Exists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If
System.IO.File.AppendAllText(logFilePath, logText)
End If
End Sub
Return sb.ToString
End Function
examineButton.Enabled = anySelected
saveCheckBox.Enabled = anySelected
End Sub
Vea también
System.IO
FileSystem
CurrentDirectory
Tutorial: Manipulación de archivos utilizando métodos de .NET Framework
Comentarios
Envíe sus comentarios sobre
Cargando comentarios...
Español (España) 0 Tema Documentación de versiones anteriores Blog Contribuir Privacidad & cookies Términos de uso Comentarios del sitio