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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| 'CREATION DES OBJETS
Set object_exec_cmd = CreateObject("WScript.Shell")
Set objet_connect_lecteur = CreateObject("WScript.Network")
Set objet_copie = CreateObject("Scripting.FileSystemObject")
Function Deconnexion()
ligne_cmd_deconnexion = "net use /delete /Y N:"
Call object_exec_cmd.Run (ligne_cmd_deconnexion)
If objet_copie.DriveExists("N:") = true then
MsgBox "Préparation en cours ... Cliquer sur OK pour continuer."
Deconnexion()
End if
End Function
Function Connexion()
ligne_cmd_connexion = "net use N: \\frer0645\out"
Call object_exec_cmd.Run (ligne_cmd_connexion)
'MsgBox "Mon lecteur est connecté"
End function
Function Verif()
Do while objet_copie.DriveExists("N:") = false 'Tant que le lecteur n'existe pas, on boucle (on attends qu'il se crée)
Loop
If objet_copie.DriveExists("N:") = true then
MsgBox "Veuillez choisir le fichier à copier.",0, "Info"
Else
Connexion()
Verif()
End if
End function
Function Copie_fichier()
Dim oFolder
Dim objFolderItem
Dim objPath
Dim copie
copie = 1
Option_noFolderButton = &H200
If objet_copie.DriveExists("N:") = true then
Deconnexion()
End if
Connexion()
Verif() 'On vérifie que le lecteur réseau est bien connecté
'BOX SELECTION
if objet_copie.DriveExists("N:") = true then
Set objDialog=CreateObject("SAFRCFileDlg.FileOpen")
ObjDialog.OpenFileOpenDlg
'msgbox objDialog.FileName
If objDialog.FileName <> "" then 'Si l'user a choisit un fichier
'Récupération du chemin du fichier à copier
fichier_copie=objDialog.FileName
'BOX DESTINATION
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.BrowseForFolder(0, "Selectionner le répertoire de destination :",Option_noFolderButton,"")
'Récupération du chemin du répertoire de destination
If (not oFolder is nothing) then
Set objFolderItem = oFolder.Self
rep_dest = objFolderItem.Path
Else
copie = 0 'Si l'user annule, on ne copie pas
End if
'Copie du fichier du serveur vers le répertoire en local
If copie = 1 then
if rep_dest <> "C:\" then
if rep_dest <> "D:\" then
rep_dest = rep_dest+"\"
'MsgBox rep_dest
End if
End if
'MsgBox rep_dest
objet_copie.CopyFile fichier_copie,rep_dest,True
MsgBox "Le fichier "&ObjDialog.FileName&" est copié.",0, "Info"
Else
MsgBox "Vous avez annuler l'opération.",0, "Info"
End if
Set oFolder = nothing
Set oShell = nothing
Set objDialog = nothing
else
MsgBox "Vous avez annuler l'opération.",0, "Info"
End if
Else
Copie_fichier()
End if
Call Explorer(rep_dest)
End function
'PROCEDURE PRINCIPALE
'COPIE FICHIER
Sub DownloadFile()
Copie_fichier()
End Sub
Function Explorer(File)
Set ws=CreateObject("wscript.shell")
ws.run "Explorer "& File
end Function |
Partager