Bonjours,
Je m'appel Anthony est je doit créer un petit programme pour mon travail.
Je suis un débutant (je commence juste a utiliser le vb depuis quelque jour).
l'application servirait a supprimer les fichiers des dossier s'il dépasse une taille donnée.
voila le code que j'ai fait il fonction bien mais il ne peut être utiliser que pour mon travail.
je souhaiterai pourvoir l'installer sur n'importe qu'elle pc.
Voila mon premier code qui marche
code du formulaire:
code du module
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
58
59
60
61
62
63
64
65
66
67 Public Class Form1 Dim mavar As Object Public vmarva As String Dim list1 As String Dim list2 As String Dim list3 As String Dim list4 As String Dim list5 As String Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim _main_Dir As New IO.DirectoryInfo(Application.StartupPath) For Each _Dir In _main_Dir.GetDirectories mavar = _Dir ListBox1.Items.Add(mavar) Next ListBox1.SetSelected(0, True) list1 = ListBox1.SelectedItem.ToString ListBox1.SetSelected(1, True) list2 = ListBox1.SelectedItem.ToString ListBox1.SetSelected(2, True) list3 = ListBox1.SelectedItem.ToString ListBox1.SetSelected(3, True) list4 = ListBox1.SelectedItem.ToString ListBox1.SetSelected(4, True) list5 = ListBox1.SelectedItem.ToString mavar = TailleDossier(Application.StartupPath) If mavar > 31457280 Then 'equivalent a 30giga octé Dim PATHDOSSIER As String = Application.StartupPath & "\" & list1 If System.IO.Directory.Exists(PATHDOSSIER) Then For Each files As String In System.IO.Directory.GetFiles(PATHDOSSIER) System.IO.File.Delete(files) Next Dim PATHDOSSIER2 As String = Application.StartupPath & "\" & list2 If System.IO.Directory.Exists(PATHDOSSIER2) Then For Each files As String In System.IO.Directory.GetFiles(PATHDOSSIER2) System.IO.File.Delete(files) Next Dim PATHDOSSIER3 As String = Application.StartupPath & "\" & list3 If System.IO.Directory.Exists(PATHDOSSIER3) Then For Each files As String In System.IO.Directory.GetFiles(PATHDOSSIER3) System.IO.File.Delete(files) Next Dim PATHDOSSIER4 As String = Application.StartupPath & "\" & list4 If System.IO.Directory.Exists(PATHDOSSIER4) Then For Each files As String In System.IO.Directory.GetFiles(PATHDOSSIER4) System.IO.File.Delete(files) Next Dim PATHDOSSIER5 As String = Application.StartupPath & "\" & list5 If System.IO.Directory.Exists(PATHDOSSIER5) Then For Each files As String In System.IO.Directory.GetFiles(PATHDOSSIER5) System.IO.File.Delete(files) Next 'End 'System.IO.Directory.Delete(PATHDOSSIER) End If End If End If End If End If Else 'End End If End Sub
est voila le code que j'essaye de faire mais je ne trouve pas l'erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 Module Module1 Function TailleDossier(Dossier) Dim fso, d, f, s fso = CreateObject("Scripting.FileSystemObject") On Error GoTo trt_Erreur If Len(Dossier) < 4 Then d = fso.GetDrive(Dossier) s = Format(d.TotalSize - d.AvailableSpace, "### ### ### ### ##0") Else f = fso.GetFolder(Dossier) s = Format(f.Size, "### ### ### ### ##0") End If TailleDossier = s - 32768 Exit Function trt_Erreur: MsgBox("Lecteur ou chemin inconnu !") End Function End Module
merci de votre aide j’espère que je ne me suis pas tromper est que je suis bien aller dans le bon endroit sur le forum
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Class Form2 Dim mavar As Object Dim Nligne As Integer Dim List As String Dim Vnom As String Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim _main_Dir As New IO.DirectoryInfo(Application.StartupPath) For Each _Dir In _main_Dir.GetDirectories mavar = _Dir ListBox1.Items.Add(mavar) Next Nligne = ListBox1.Items.Count() For i = 1 To Nligne ListBox1.SetSelected(i, True) Vnom = "list" & i Vnom = ListBox1.SelectedItem.ToString mavar = TailleDossier(Application.StartupPath) Next For j = 1 To Nligne If mavar > 30000 Then Dim pathd As String = Application.StartupPath & "\" & Vnom If System.IO.Directory.Exists(pathd(j)) Then For Each files As String In System.IO.Directory.GetFiles(pathd(j)) System.IO.File.Delete(files) Next End If End If Next End Sub End Class
je souhaite encore préciser que le code n'a pas été trouver comme sa sur le net,j'ai rechercher des bouts de code déjà existant que j'ai mis ensemble pour réaliser mon code
Partager