Marneus73
Messages postés344Date d'inscriptionmercredi 24 janvier 2007StatutMembreDernière intervention27 octobre 2008
-
15 mars 2007 à 22:03
troxsa
Messages postés553Date d'inscriptionjeudi 28 novembre 2002StatutMembreDernière intervention 2 octobre 2016
-
16 mars 2007 à 13:42
Bonjour à tous.
J'ai crée un petit prog pour vérifier l'existence d'un fichier:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Visible = False
Dim chemin As String = "BOB.exe"
Dim process As New Process
For Each disque As String In Directory.GetLogicalDrives()
Dim D As New DriveInfo(disque)
If D.DriveType = DriveType.CDRom Then
Try
If My.Computer.FileSystem.FileExists(disque + chemin) = True Then
MessageBox.Show("Le Fichier existe")
Else
MessageBox.Show("Le Fichier n'existe pas")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Next
End Sub
End Class
Le seul probléme, c'est que je vois à l'écran successivement: "Le Fichir n'existe pas", puis "Le Fichier existe" et enfin "Le Fichir n'existe pas".
Je n'y comprends rien !? J'ai 3 messagebox de suite avec jamais la meme chose !!!
troxsa
Messages postés553Date d'inscriptionjeudi 28 novembre 2002StatutMembreDernière intervention 2 octobre 20161 16 mars 2007 à 11:54
Bonjour
Il me semble que tu ne test pas si ton lecteur est pres ou pas !
Je me suis permis de faire une retouche sur ton code
__________________________________________________
Me.Visible = False
Dim chemin As String = "BOB.exe"
Dim process As New Process
For Each disque As String In Directory.GetLogicalDrives()
Dim D As New DriveInfo(disque)
If D.DriveType = DriveType.CDRom Then
If D.IsReady = True Then
Try
If File.Exists(Path.Combine(disque, chemin)) = True Then
MessageBox.Show("Le Fichier existe")
Else
MessageBox.Show("Le Fichier n'existe pas")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End If
Next
__________________________________________________