Visual Basic.NET - Listar archivos de 2 ficheros

 
Vista:

Listar archivos de 2 ficheros

Publicado por PETETE (8 intervenciones) el 28/07/2017 11:41:36
Hola buenas,

como bien dice el titulo no se como hacer una lista de los archivos de 2 ficheros.

He abierto las dos carpetas con folderbrowserDialog y al pasar el nombre de los archivos a un excel, me escribe la ruta entera de los archivo...

Como podría hacer que solo escribiera el nombre del archivo?

Código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Sub leer_pdf_y_crear_excel(path, ficheroscarpeta, path2, ficheroscarpeta2, openfolderdialog, openfolderdialog2)
        ' Dim fichero
        Dim xlapp
        Dim xllibro
        Dim xlhoja
        Dim i As Integer = 1
        'Dim fichero
        Dim archivo As String = "*.pdf"
        Dim listbox1 As ListBox
        xlapp = CreateObject("Excel.Application")
        xllibro = xlapp.workbooks.add
        xlhoja = xllibro.worksheets("Hoja1")
        xlapp.visible = True
 
        ficheroscarpeta = System.IO.Directory.GetFiles(path)
        ficheroscarpeta2 = System.IO.Directory.GetFiles(path2)
 
        For Each fichero As String In ficheroscarpeta
            listbox1. = fichero
            xlhoja.cells(i, 1) = fichero
            i += 1
        Next
        For Each fichero As String In ficheroscarpeta2
            xlhoja.cells(i, 1) = fichero
            i += 1
        Next
 
 
    End Sub
 
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim OpenFolderDialog As New FolderBrowserDialog
        Dim path As String
        Dim ficheroscarpeta() As String
 
        Dim OpenFolderDialog2 As New FolderBrowserDialog
        Dim path2 As String
        Dim ficheroscarpeta2() As String
 
        OpenFolderDialog.SelectedPath = "C:\Users\pepe\Desktop"
        OpenFolderDialog2.SelectedPath = "C:\Users\pepe\Desktop"
 
 
        If OpenFolderDialog.ShowDialog() = DialogResult.OK Then
            path = OpenFolderDialog.SelectedPath
 
        End If
 
        If OpenFolderDialog2.ShowDialog() = DialogResult.OK Then
            path2 = OpenFolderDialog2.SelectedPath
            leer_pdf_y_crear_excel(path, ficheroscarpeta, path2, ficheroscarpeta2, OpenFolderDialog, OpenFolderDialog2)
        End If
 
    End Sub
 
 
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Diego
Val: 605
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Listar archivos de 2 ficheros

Publicado por Diego (190 intervenciones) el 30/07/2017 06:33:12
Hola Petete, podes utilizar directoryInfo y FileInfo para obtener solo el nombre del archivo, asi...

1
2
3
4
5
6
7
Dim carpeta1 as new System.IO.DirectoryInfo(path)
 
For Each fichero As fileInfo In carpeta1.GetFileSystemInfos("*.pdf")
            listbox1. = fichero.name
            xlhoja.cells(i, 1) = fichero.name
            i += 1
Next

Saludos y +Bytes.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar