Bonjour,

le programme si-dessous scan une arborescence à la recherche d'extension comptenu dans un fichier .txt.
il enregistre les chemin des fichiers trouvés dans un fichier NameLog.csv.

je souhaiterai copier ce fichier NameCSV.csv vers un autre repertoire à la fin de l'ecriture de celui-ci

merci de votre aide

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
 
Option Explicit
'On Error Resume next
 
'**************************************************************************************************
'****** Declaration des constantes ****************************************************************
'**************************************************************************************************
Const ForReading = 1, ForWriting = 2, ForAppending = 8		'Def les methode d'accès aux fichiers
 
'**************************************************************************************************
'****** Déclaration des variables *****************************************************************
'**************************************************************************************************
Dim chm_script					'Def variable du chemin du script
Dim ofso						'Def variable ofso
Dim ofile_log					'Def variable Ofile_log
Dim oscript						'Def variable oscript
Dim oDir						'Def variable oDir
Dim oCreate						'Def variable oCreate
Dim test 						'Réponse à la confirmation du scan
Dim NameLog
Dim NameCSV
Dim objExt						'Variable de création de fichier Extension
Dim NameExt						'Def le nom du fichier extension
Dim Cherche
Dim ofich
Dim oExt						'conteur d'extensions
dim objcount
 
 
NameLog = "ReportU1.LOG"		'Def le nom du fichier log
NameCSV = "ReportU1.CSV"		'Def le nom du fichier de config
NameExt = "ExtensionU.txt"	'Def le nom du fichier extension
 
'##################################################################################################
'######## Début du corps de script ################################################################
'##################################################################################################
Set ofso = CreateObject("scripting.fileSystemObject")
Set oCreate = ofso.CreateTextFile(NameLog,True)
 
oCreate.Close
 
If ofso.FileExists(NameCSV) Then
ofso.DeleteFile(NameCSV)
End If
 
 
chm_script=Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)-Len(WScript.ScriptName))	'Détermine le chemin du script
 
'**************************************************************************************************
'******** Mise en forme du fichier de Log *********************************************************
'**************************************************************************************************
 
Write_Log("Chemin Complet du fichier" & ";" & "Extension du Fichier" & ";" & "Date Dernière Modification" & ";" & "Date Dernier Accès" & ";" & "Taille du Fichier (Ko)")
 
 
Set oExt = ofso.OpenTextFile(NameExt,ForReading,True)
 
Do Until oExt.AtEndoFStream
objcount = 0
cherche = oExt.ReadLine
ScanRep WScript.Arguments(0),cherche
Write_log("Extension "& cherche &" : "& objCount &" fichier trouvés")
Loop
 
ofso.MoveFile NameLog, NameCSV
 
'##################################################################################################
'######## 'Zone des Fonctions du script############################################################
'##################################################################################################
 
'**************************************************************************************************
'******** Fonction d'écriture du fichier de log ***************************************************
'**************************************************************************************************
Sub Write_log(text)
	Dim owrite, olog				'Definition des variables de la fonction
 
	olog = chm_script & NameLog	'olog contient le chemin + nom du fichier de log
	Set owrite = ofso.OpenTextFile(olog,ForAppending,True)
	owrite.WriteLine text
	owrite.Close
	Set ofich=Nothing
 
End Sub
 
'**************************************************************************************************
'******** Fonction de Scan des répertoires ********************************************************
'**************************************************************************************************
Function ScanRep(source, FileExt)
 
	Dim objExt
	Dim odirectory
	Dim explDirectory
	Dim ofiles
	Dim explFile
	Dim subDirectory
 
	If ofso.FolderExists(source) Then
		Set odirectory = oFso.GetFolder(source)
		Set ofiles=odirectory.Files 
		For Each explFile In ofiles
			If Ucase(ofso.GetExtensionName(explFile.Name))= FileExt  Then
			write_log(odirectory.Path &"\" &explFile.Name & ";" & UCase(Right(explFile.Name,4-(Instr(Right(explFile.Name,4),".")))) & ";" & explFile.DateLastModified & ";" & explFile.DateLastAccessed & ";" & Round(explFile.Size/1024))
			objcount = objcount + 1
			Else
			End If		
		Next
 
	Set subDirectory = odirectory.SubFolders
 
		For Each explDirectory In subDirectory
			ScanRep explDirectory.Path, FileExt
		Next
	End If
 
End Function
 
 
 
'**************************************************************************************************
'******** Copie du fichier CSV ********************************************************************
'**************************************************************************************************
Function copie()
 
 
Dim fsocop						'déclaration file system object
 
'instanciation
Set FSOCOP = CreateObject("Scripting.FileSystemObject")
 
	If fsocop.FileExists(ReportU1.CSV)Then
 
'Copie du fichier
		Set Ftxt = fsocop.GetFile("chemin\ReportU1.CSV")   'Fichier origine
		Ftxt.copy("chemin") 'emplacement destination
 
		End If
End Function
 
copie (NameCSV)