J'ai fait ce programme pour renommer les fichiers (a l'origine les mp3).
Il permet d'enlever , rajouter des caracteres a un endroit choisi dans la chaines.
Le programme est quasiment fini mais mon cerveau avait besoin d'un break, donc quelques bug restent.
Comme le rafraichissement auto de la liste de selection ou le message d'erreur qui n'apparait pas si "toutes les cases" n'ont pas été cochées.
Je suis assez debutant donc n'hesitez pas a me critiquer ou me dire comment j'aurais pu faire mieux.Toutes les remarques seront bienvenues
Tchô
Source / Exemple :
Public selectedfile As String
Public Valtextaddremo As String
Public texttoremove As String
Private Sub Checkadd_Click()
'if we clic on add, remove must come off
If Checkadd.Value = Checked Then
Checkremove.Value = Unchecked
End If
End Sub
Private Sub Checkremove_Click()
'if we clic on remove, add must come off
If Checkremove.Value = Checked Then
Checkadd.Value = Unchecked
End If
End Sub
Private Sub Checkafter_Click()
'if we clic on after, before must come off
If Checkafter.Value = Checked Then
Checkbefore.Value = Unchecked
End If
End Sub
Private Sub Checkbefore_Click()
'if we clic on before, after must come off
If Checkbefore.Value = Checked Then
Checkafter.Value = Unchecked
End If
End Sub
Private Sub Command1_Click()
'erase the textaddremove textbox
Textaddremove.Text = ""
End Sub
Private Sub Command2_Click()
'erase the Textpos textbox
Textpos.Text = ""
End Sub
Private Sub Command3_Click()
'copy text1 selection
Form1.Text1.SetFocus
SendKeys "^C"
End Sub
Private Sub Command4_Click()
'paste the selection into textaddremove textbox
Form1.Textaddremove.SetFocus
SendKeys "^V"
End Sub
Private Sub Command5_Click()
'paste the selection into textpos textbox
Form1.Textpos.SetFocus
SendKeys "^V"
End Sub
Private Sub Commandaddall_Click()
'add all the files into file1 to list1
For i = 0 To File1.ListCount - 1
List1.AddItem File1.List(i)
Next
End Sub
Private Sub Commandaddorremove_Click()
'we replace (textpos) by (textpos + textaddremove)
If Checkadd.Value And Checkbefore.Value = Checked Then
Textposition = Textaddremove & Textpos
Textposition2 = Textpos
GoTo changename
ElseIf Checkremove.Value And Checkbefore.Value = Checked Then
Textposition = Textpos
Textposition2 = Textaddremove & Textpos
GoTo changename
ElseIf Checkadd.Value And Checkafter.Value = Checked Then
Textposition = Textpos & Textaddremove
Textposition2 = Textpos
GoTo changename
ElseIf Checkremove.Value And Checkafter.Value = Checked Then
Textposition = Textpos
Textposition2 = Textpos & Textaddremove
ElseIf Checkadd.Value Or Checkremove.Value Or Checkbefore.Value Or Checkafter.Value = Unchecked Then
MsgBox "Cochez toutes les cases..."
End If
changename:
For i = 0 To List1.ListCount - 1
selectedfileC = List1.List(i)
'on cherche dans (selectedfileC) le (textposition2) qu'on va remplacer par (textposition), that will give us newname1010
newname1010 = Replace(selectedfileC, Textposition2, Textposition)
'i use f and g as string cuz the fonction (name) wont work with such complexe expressions
f = Dir1.Path & "\" & selectedfileC
g = Dir1.Path & "\" & newname1010
Name f As g
Next
File1.Refresh
End Sub
Private Sub Commandaddselected_Click()
'i copy the selection in file1 to list1
Dim i As Integer
If File1.ListIndex = -1 Then Exit Sub
For i = File1.ListCount - 1 To 0 Step -1
If File1.Selected(i) = True Then
List1.AddItem File1.List(i)
End If
Next i
End Sub
Private Sub Commandclearlist_Click()
List1.Clear
End Sub
Private Sub Commandclearselected_Click()
'same as copy into list1 but this is to remove a selection from a list
Dim i As Integer
If List1.ListIndex = -1 Then Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
List1.RemoveItem (i)
End If
Next i
End Sub
Private Sub Commandundertospaces_Click()
'same as above, i search (_) into (selectedfileB) and replace it with ( )
For i = 0 To List1.ListCount - 1
selectedfileB = List1.List(i)
newnameB = Replace(selectedfileB, "_", " ")
d = Dir1.Path & "\" & selectedfileB
e = Dir1.Path & "\" & newnameB
Name d As e
Next
File1.Refresh
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub List1_Click()
'i copy the name of the file i clic on into the text1box for the user to use it for copying and pasting
Text1.Text = List1.Text
End Sub
Private Sub onlymp3_Click()
'i set file1 to show only the files.mp3 if (onlymp3) is checked, else it shows *.*
If onlymp3.Value = 1 Then
File1.Pattern = "*.mp3"
Else
File1.Pattern = "*.*"
End If
End Sub
Private Sub Commandexit_Click()
End
End Sub
Private Sub Textaddremove_Change()
Textaddremove = Textaddremove.Text
End Sub
Private Sub Textpos_Change()
Textpos = Textpos.Text
End Sub
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.