cs_ephy
Messages postés3Date d'inscriptionvendredi 19 novembre 2004StatutMembreDernière intervention 3 novembre 2005
-
2 nov. 2005 à 21:59
cs_ephy
Messages postés3Date d'inscriptionvendredi 19 novembre 2004StatutMembreDernière intervention 3 novembre 2005
-
3 nov. 2005 à 10:15
Bonjour à tous !
Je désire tester si un repertoire existe lorsque je clique sur un bouton, j'ai donc le code suivant :
Private Sub Command1_Click()
Dim reponse As Integer
If Dir("c:/nouveau_dossier/") <> "" Then
MsgBox ("Existe")
Else
MsgBox ("Existe pas")
reponse = MsgBox("Creer ?", vbInformation + vbYesNo, "Creer")
If reponse = vbYes Then
MkDir ("c:/nouveau_dossier")
Else: End
End If
End If
End Sub
Mon soucis est qu'après avoir créée mon repertoire, si je relance l'application il ne le detecte toujours pas et me demande d'en creer un alors qu'il est deja creer. Par contre si je teste si le repertoire Windows ou Program Files, il me confirme bien que le dossier existe. QQn aurait-il une solution ou un autre code svp ?!
Merci d'avance
A voir également:
Vb la teste
Pathfileexists - Meilleures réponses
Vba tester si un fichier existe - Meilleures réponses
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 2 nov. 2005 à 22:22
salut
[VB6]
Option Explicit
'
Private Declare Function PathFileExists Lib "shlwapi.dll" _
Alias "PathFileExistsA" _
ByVal pszPath As String) As Long
'
'
Private Sub Command1_Click()
If CBool(PathFileExists("c:/nouveau_dossier/")) Then
MsgBox "c'est ok ;)", 32
Else
Dim lRep As Long
lRep = MsgBox ("n'existe pas, créer ??", vbInformation + vbYesNo, "Creer")
If lRep = vbYes Then
MkDir ("c:/nouveau_dossier")
Else
Unload Me
End If
End If
End Sub
cs_jeanmarc
Messages postés34Date d'inscriptionmardi 18 juin 2002StatutMembreDernière intervention22 novembre 2005 2 nov. 2005 à 22:20
bonsoir,
exemple en vbs (valable en vba) pour tester la presence d'un path
Dim wRepDest1, fso
wRepDest1 = "c:\Archive-xxxx"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(wRepDest1) Then
Set f = fso.CreateFolder(wRepDest1)
msgBox "Création du dossier "&f&" effectuée.",vbInformation
Else
msgBox "Attention:"&vbCrLf&"Le répertoire "&wRepDest1&" existe déjà."&vbCrLf&"Les nouveaux fichiers ne sont donc pas archivés",vbCritical
End if