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
   | 'Get Application object of the Windows shell.
Set objShell = WScript.CreateObject("Shell.Application")
 
'Ask the user to select a folder
Set obFolder = objShell.BrowseForFolder (0, "Select the folder to process", 1)
 
 
If NOT obFolder IS Nothing Then
 
	'Get access to input folder and process it
	Set FSO = CreateObject("Scripting.FileSystemObject")
	'récupère dans PATH le "chemin" du fichier
	'PATH = FSO.GetParentFolderName(wscript.ScriptFullName) & "\"
 
	'Suprime les anciens fichiers sans _XX à la fin
	DeleteOldFiles FSO, obFolder.self.Path ',PATH
 
 
	MsgBox "Finished"
 
Else
 
	MsgBox "Canceled"
 
End If
 
'Suprime les anciens fichiers sans _XX à la fin
Sub DeleteOldFiles (FSO, FolderPath) ', PATH)
 
'Get access to the folder
	Set obFolder = FSO.GetFolder(FolderPath)
 
	'Loop on all the files and process each of them
	For Each obFile In obFolder.Files
 
		If (StrComp(Right(obFile.Name, 3), "wcl", 1) = 0) AND _
		   (InStr(1, obFile.Name, "diagraphie", 1) > 0) AND _
		   (InStr(1, obFile.Name, "_xx", 1) = 0) Then
		    Wscript.echo obFile.name 'donne le bon nom de fichier
			Wscript.echo obFolder 'donne le bon chemin mais sans le \ à la fin
 
 
		FSO.Deletefile(obfile.name) 'réponse : Fichier introuvable ... code erreur 800A0035
		'ici je crois qu'il me manque qq chose
		'pour donner le chemin du fichier ... mais je ne trouve pas comment faire ....
		'et ce répertoire varie pendant le déroulement du script
		'Faut-il utiliser PATH, si oui comment?
 
		End If
 
	Next
 
	'Loop on all the subfolders and process each of them
	For Each obSubFolder In obFolder.SubFolders
		DeleteOldfiles FSO, obSubFolder.Path ',PATH
	Next
 
End Sub | 
Partager