Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionImports System.IO Imports System.IO.Path Dim sNewFile As String 'chemin fichier sNewFile = Form1.Lblcible.Text & "" 'chemin du dossier sNewFile &= GetFileNameWithoutExtension(Form1.FileListBox1.SelectedItem.ToString) 'nom fichier sans extension sNewFile &= ".tif" 'extension
Imports System.IO Public Class Form1 Dim filePath As String = Nothing Dim i As Integer = 0 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim folders As New FolderBrowserDialog folders.ShowNewFolderButton = True folders.RootFolder = Environment.SpecialFolder.Desktop folders.Description = "Veuillez choisir un dossier !" If folders.ShowDialog = Windows.Forms.DialogResult.OK Then filePath = folders.SelectedPath i = CountFichier(filePath, "*.pdf|*.txt", SearchOption.TopDirectoryOnly).Length Label1.Text = i & "/ 0" Else : Exit Sub End If End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click If (i > 0) AndAlso Not String.IsNullOrEmpty(TextBox1.Text) Then Dim count As Integer = 0 For Each foundFile As String In CountFichier(filePath, "*.pdf|*.txt", SearchOption.TopDirectoryOnly) If File.Exists(foundFile) Then My.Computer.FileSystem.CopyFile(foundFile, filePath & "\" & TextBox1.Text & "-" & My.Computer.FileSystem.GetName(foundFile), True) count += 1 End If Next Label1.Text = i & "/" & count MessageBox.Show(count & " Fichier à bien était Renommer!", "Renommer", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("Veuillez entrer un mot de renommer un ou plusier fichier(s) où Veuillez selectionner un dossier pour renommer un ou plusieur fichier (s) !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Sub Private Function CountFichier(Path As String, searchPattern As String, searchOption As SearchOption) As String() Dim searchPatterns() As String = searchPattern.Split("|") Dim files As List(Of String) = New List(Of String) For Each sp As String In searchPatterns files.AddRange(Directory.GetFiles(Path, sp, searchOption)) Next files.Sort() Return files.ToArray End Function End Class