Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Rinomina File - Form1.vb

Form1.vb

Caricato da:
Scarica il programma completo

  1. Imports System
  2. Imports System.IO
  3.  
  4. Public Class Form1
  5.     Inherits System.Windows.Forms.Form
  6.     Dim percorso As String
  7.     Dim file() As String
  8.  
  9. #Region " Codice generato da Progettazione Windows Form "
  10.  
  11.     Public Sub New()
  12.         MyBase.New()
  13.  
  14.         'Chiamata richiesta da Progettazione Windows Form.
  15.         InitializeComponent()
  16.  
  17.         'Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent()
  18.  
  19.     End Sub
  20.  
  21.     'Form esegue l'override del metodo Dispose per pulire l'elenco dei componenti.
  22.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  23.         If disposing Then
  24.             If Not (components Is Nothing) Then
  25.                 components.Dispose()
  26.             End If
  27.         End If
  28.         MyBase.Dispose(disposing)
  29.     End Sub
  30.  
  31.     'Richiesto da Progettazione Windows Form
  32.     Private components As System.ComponentModel.IContainer
  33.  
  34.     'NOTA: la procedura che segue è richiesta da Progettazione Windows Form.
  35.     'Può essere modificata in Progettazione Windows Form.  
  36.     'Non modificarla nell'editor del codice.
  37.     Friend WithEvents Button1 As System.Windows.Forms.Button
  38.     Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
  39.     Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
  40.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  41.     Friend WithEvents Button2 As System.Windows.Forms.Button
  42.     Friend WithEvents Button3 As System.Windows.Forms.Button
  43.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  44.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
  45.         Me.Button1 = New System.Windows.Forms.Button
  46.         Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog
  47.         Me.ListBox1 = New System.Windows.Forms.ListBox
  48.         Me.TextBox1 = New System.Windows.Forms.TextBox
  49.         Me.Button2 = New System.Windows.Forms.Button
  50.         Me.Button3 = New System.Windows.Forms.Button
  51.         Me.SuspendLayout()
  52.         '
  53.         'Button1
  54.         '
  55.         Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System
  56.         Me.Button1.Location = New System.Drawing.Point(8, 248)
  57.         Me.Button1.Name = "Button1"
  58.         Me.Button1.TabIndex = 0
  59.         Me.Button1.Text = "Sfoglia"
  60.         '
  61.         'FolderBrowserDialog1
  62.         '
  63.         Me.FolderBrowserDialog1.Description = "Cerca Cartella"
  64.         Me.FolderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.MyComputer
  65.         Me.FolderBrowserDialog1.ShowNewFolderButton = False
  66.         '
  67.         'ListBox1
  68.         '
  69.         Me.ListBox1.Location = New System.Drawing.Point(8, 8)
  70.         Me.ListBox1.Name = "ListBox1"
  71.         Me.ListBox1.ScrollAlwaysVisible = True
  72.         Me.ListBox1.Size = New System.Drawing.Size(592, 238)
  73.         Me.ListBox1.TabIndex = 1
  74.         '
  75.         'TextBox1
  76.         '
  77.         Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  78.         Me.TextBox1.Location = New System.Drawing.Point(8, 280)
  79.         Me.TextBox1.Name = "TextBox1"
  80.         Me.TextBox1.Size = New System.Drawing.Size(592, 22)
  81.         Me.TextBox1.TabIndex = 2
  82.         Me.TextBox1.Text = ""
  83.         '
  84.         'Button2
  85.         '
  86.         Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.System
  87.         Me.Button2.Location = New System.Drawing.Point(488, 248)
  88.         Me.Button2.Name = "Button2"
  89.         Me.Button2.Size = New System.Drawing.Size(112, 23)
  90.         Me.Button2.TabIndex = 3
  91.         Me.Button2.Text = "Rinomina Selezionato"
  92.         '
  93.         'Button3
  94.         '
  95.         Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.System
  96.         Me.Button3.Location = New System.Drawing.Point(408, 248)
  97.         Me.Button3.Name = "Button3"
  98.         Me.Button3.TabIndex = 4
  99.         Me.Button3.Text = "Aggiorna Lista"
  100.         '
  101.         'Form1
  102.         '
  103.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  104.         Me.ClientSize = New System.Drawing.Size(606, 308)
  105.         Me.Controls.Add(Me.Button3)
  106.         Me.Controls.Add(Me.Button2)
  107.         Me.Controls.Add(Me.TextBox1)
  108.         Me.Controls.Add(Me.ListBox1)
  109.         Me.Controls.Add(Me.Button1)
  110.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
  111.         Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
  112.         Me.MaximizeBox = False
  113.         Me.Name = "Form1"
  114.         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  115.         Me.Text = "Rinomina File By GoLDBeRG"
  116.         Me.ResumeLayout(False)
  117.  
  118.     End Sub
  119.  
  120. #End Region
  121.  
  122.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  123.         On Error Resume Next
  124.         FolderBrowserDialog1.ShowDialog()
  125.         percorso = Me.FolderBrowserDialog1.SelectedPath
  126.         Dim a As Integer
  127.         file = Directory.GetFiles(percorso)
  128.         For a = 1 To file.Length - 1
  129.             ListBox1.Items.Add(file(a))
  130.         Next a
  131.     End Sub
  132.  
  133.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  134.         On Error GoTo errore
  135.         Rename(ListBox1.SelectedItem, TextBox1.Text)
  136.         Dim index As Integer = ListBox1.SelectedIndex
  137.         ListBox1.Items.Clear()
  138.         Dim a As Integer
  139.         file = Directory.GetFiles(percorso)
  140.         For a = 1 To file.Length - 1
  141.             ListBox1.Items.Add(file(a))
  142.         Next a
  143.         ListBox1.SelectedIndex = index + 1
  144.         Exit Sub
  145. errore: MessageBox.Show("Questo file esiste gia!!Cambiare Nome!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  146.     End Sub
  147.  
  148.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  149.         TextBox1.Text = ListBox1.SelectedItem
  150.     End Sub
  151.  
  152.     Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  153.         If e.KeyChar = Chr(13) Then Button2.PerformClick()
  154.     End Sub
  155.  
  156.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  157.         Dim index As Integer = ListBox1.SelectedIndex
  158.         ListBox1.Items.Clear()
  159.         Dim a As Integer
  160.         file = Directory.GetFiles(percorso)
  161.         For a = 1 To file.Length - 1
  162.             ListBox1.Items.Add(file(a))
  163.         Next a
  164.         ListBox1.SelectedIndex = index
  165.     End Sub
  166. End Class
  167.  
  168. Public Class Main
  169.     Shared Sub Main()
  170.         Application.EnableVisualStyles()
  171.         Application.Run(New Form1)
  172.     End Sub
  173. End Class