Insérer un Dir() dans une boucle de recherche de fichier

jsmeiway Messages postés 32 Date d'inscription mardi 24 août 2004 Statut Membre Dernière intervention 9 septembre 2005 - 25 mars 2005 à 10:53
jsmeiway Messages postés 32 Date d'inscription mardi 24 août 2004 Statut Membre Dernière intervention 9 septembre 2005 - 25 mars 2005 à 11:04
Bonjour,

J'aimerais faire un déplacement de dossier ou fichier avec vérification de la destination
il se peut qu'il y est déjà une fonction?

voilà ce que j'ai effectué
SCRdirPFS="c:\test1"
DSTdirPFS="c:\test2"
ProfilExt=".xxx"


je sais que je ne suis pas obligé de faire çà ;)
FindFileProfil = Left(FindFileProfil, Len(FindFileProfil) - Len(ProfilExt))


tout fonctionne si je ne met pas les conditions
If Dir(DSTdirPFS & FindFileProfil & ProfilExt, vbNormal Or vbReadOnly Or vbHidden Or vbArchive) <> "" Then


==================================================================
Dim FindFileProfil As String
FindFileProfil = Dir(SCRdirPFS & "*" & ProfilExt)
While FindFileProfil <> ""


FindFileProfil = Left(FindFileProfil, Len(FindFileProfil) - Len(ProfilExt))
FileCopy SCRdirPFS & FindFileProfil & ProfilExt, DSTdirPFS & FindFileProfil & ProfilExt

On Error Resume Next
Kill SCRdirPFS & FindFileProfil & ProfilExt


FindFileProfil = Dir()
Wend
==================================================================
Dim FindFileProfil As String
Dim VbMsgBoxResult
FindFileProfil = Dir(SCRdirPFS & "*" & ProfilExt)
While FindFileProfil <> ""


FindFileProfil = Left(FindFileProfil, Len(FindFileProfil) - Len(ProfilExt))
'Confirmer l'écrasement du fichier
If Dir(DSTdirPFS & FindFileProfil & ProfilExt, vbNormal Or vbReadOnly Or vbHidden Or vbArchive) <> "" Then
VbMsgBoxResult = MsgBox(Chr$(34) & FindFileProfil & Chr$(34) & " existe déjà dans le dossier de destination, voulez-vous l'écraser ?", vbYesNo, "Déplacement")
If VbMsgBoxResult = vbYes Then
'Déplacement du profil


FileCopy SCRdirPFS & FindFileProfil & ProfilExt, DSTdirPFS & FindFileProfil & ProfilExt
'Supprime le fichier source (seulement si fichier copié)
If Dir(DSTdirPFS & FindFileProfil & ProfilExt, vbNormal Or vbReadOnly Or vbHidden Or vbArchive) <> "" Then
On Error Resume Next
Kill SCRdirPFS & FindFileProfil & ProfilExt
End If
End If
Else
'Déplacement du profil
FileCopy SCRdirPFS & FindFileProfil & ProfilExt, DSTdirPFS & FindFileProfil & ProfilExt


'Supprime le fichier source (seulement si fichier copié)
If Dir(DSTdirPFS & FindFileProfil & ProfilExt, vbNormal Or vbReadOnly Or vbHidden Or vbArchive) <> "" Then
On Error Resume Next
Kill SCRdirPFS & FindFileProfil & ProfilExt
End If
End If


FindFileProfil = Dir()
Wend
==================================================================

mytoo vmeiway

1 réponse

jsmeiway Messages postés 32 Date d'inscription mardi 24 août 2004 Statut Membre Dernière intervention 9 septembre 2005
25 mars 2005 à 11:04
j'ai résolu dle pb, en me fabriquant un tableau avnt
mais n'hésiter pas à m'aider

mytoo vmeiway
0
Rejoignez-nous