Copier un fichier vers un repertoire ne fonctionne pas

paco77 Messages postés 1 Date d'inscription samedi 5 juin 2004 Statut Membre Dernière intervention 21 avril 2011 - 21 avril 2011 à 18:04
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 21 avril 2011 à 19:30
Bonjour,

Voici mon code, mais il ne fonctionne pas
Dim objFSO
strDestFolder = "c:\fichiersfmperso\xml"
Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.copyfile "C:\fichiersfmperso\AGIRA\201100184\*.xml", "c:\fichiersfmperso\xml",true

En vbs cela ne fonctionne pas, je ne sais pas pourquoi, j'ai cherché avant de poster...

Merci pour votre aide.

1 réponse

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
21 avril 2011 à 19:30
 Bonsoir

Un exemple de debug



Option Explicit
Const PathSource = "d:\Test.txt"
Const PathDest = "D:\xxx\yy\copy_test.txt"
Dim objFso
Dim strFolder

Set objFso = CreateObject("Scripting.FileSystemObject")

'Contrôle existence fichier en entrée
If Not objFso.FileExists(PathSource) Then MsgBox PathSource,,"Erreur Fichier"  

'Contrôle existence du répertoire de destination
strFolder = Left(PathDest, Len(PathDest)-Len(Mid(PathDest, InStrRev(PathDest, "") + 1)))
If Not objFso.FolderExists(strFolder) Then MsgBox strFolder,,"Erreur répertoire" 

'Copie du fichier
objFso.CopyFile PathSource, PathDest
If Err.Number <> 0 Then 
   MsgBox Err.Number &vbCrLf& Err.Source &vbCrLf& _
          Err.Description : Err.Clear
End If
Set objFso = Nothing




jean-marc
0
Rejoignez-nous