Código
Imports System Imports System.IO Imports System.Windows Imports System.Threading.Tasks Imports System.Reflection Imports System.Text Imports System.Security.Cryptography Imports System.Security.AccessControl Public NotInheritable Class Form1 : Inherits Form Dim linea As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Ruta As String = My.Application.Info.DirectoryPath() Dim LetraRuta As String = Mid(Ruta, 1, 3) Label1.Text = LetraRuta 'Cargar datos del txt Dim lector As New StreamReader(Ruta & "\" & "test.txt") ' Leer el contenido mientras no se llegue al final While lector.Peek() <> -1 ' Leer una línea del fichero linea = lector.ReadLine() ' Si no está vacía, añadirla al control ' Si está vacía, continuar el bucle If String.IsNullOrEmpty(linea) Then Continue While End If ListBox3.Items.Add(linea) End While ' Cerrar el fichero lector.Close() Dim allDrives() As DriveInfo = DriveInfo.GetDrives() If LetraRuta <> strDrive Then 'Comprobamos que las rutas sean diferentes Try Dim DriveSubDirectories As String() = Directory.GetDirectories(strDrive) For Each strSubDirectory As String In DriveSubDirectories Dim strFolder As String = strSubDirectory.Remove(0, strSubDirectory.LastIndexOf("\") + 1) ListBox1.Items.Add(strSubDirectory) '<---Carpeta Try Dim strFiles As IEnumerable = Directory.EnumerateFiles(strDrive & strFolder, "*", SearchOption.AllDirectories) Dim NbArchivo As String For Each strFileName In strFiles ListBox2.Items.Add(strFileName) '<--Archivo con ruta completa For Each item As Object In ListBox3.Items 'If InStr(strFileName, item) Then Dim ExArchivo As String ExArchivo = Path.GetExtension(strFileName) If ExArchivo = item Then NbArchivo = Path.GetFileName(strFileName) 'Then Dim RutaDestino As String = Ruta & "\" & "Organizado" & "\" & ExArchivo & "\" ' Crea directorio Raiz If Not Directory.Exists(Ruta & "\" & "Organizado") Then Directory.CreateDirectory(Ruta & "\" & "Organizado") 'Le da atributos a la carpeta raiz Dim folder_info As IO.DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(Ruta & "\" & "Organizado") End If 'Crea subdirectorios por extensiones encontradas If Not Directory.Exists(RutaDestino) Then Directory.CreateDirectory(RutaDestino) Dim folder_info2 As IO.DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(RutaDestino) End If 'File.Copy("K:\55\", True) End If Next Me.Text = ListBox2.Items.Count.ToString() & ".Archivos" Next 'strFileName Catch ex As Exception ' MessageBox.Show(ex.Message) End Try 'strFiles Next 'strSubDirectory Catch ex As Exception ' MessageBox.Show(ex.Message) End Try 'Drives End If Next '[Drive] 'Bloqueamos la carpera fs.AddAccessRule(New FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Deny)) End Sub End Class