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
| Titre = "Lister tous les fichiers en double dans un dossier et ses sous-dossiers"
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Ws = CreateObject("Wscript.Shell")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0,Titre,1,"c:\Programs")
If objFolder Is Nothing Then
WScript.Quit
End If
NomDossier = objFolder.Title
CheminDossier = objFolder.self.path
Const ForWriting = 2
Dim stFile
stFile = "AnalyseDoublons.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(stFile,ForWriting,true)
Set objFolder = objFSO.GetFolder(CheminDossier)
Set colFiles = objFolder.Files
For Each objFile in colFiles
strName = objFile.Name
strPath = objFile.Path
If Not objDictionary.Exists(strName) Then
objDictionary.Add strName,strPath
Else
objDictionary.Item(strName) = objDictionary.Item(strName) & ";" & strPath
End If
Next
ShowSubfolders objFSO.GetFolder(CheminDossier)
ws.run stFile
For Each strKey in objDictionary.Keys
strFileName = strKey
If InStr(objDictionary.Item(strFileName), ";") Then
arrPaths = Split(objDictionary.Item(strFileName), ";")
For Each strFilePath in arrPaths
f.WriteLine strFilePath
Next
f.WriteLine String(100,"*")
End If
Next
f.WriteLine VbNewLine & "Liste des fichiers en double sur " & objDictionary.Count & " fichiers Total Scannés dans le dossier " & CheminDossier
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
strName = objFile.Name
strPath = objFile.Path
On Error Resume Next
If Err <> 0 Then MsgBox Err.Number & Err.Description,16,Err.Number & Err.Description
Err.Clear
If Not objDictionary.Exists(strName) Then
objDictionary.Add strName, strPath
Else
objDictionary.Item(strName) = objDictionary.Item(strName) & ";" & strPath
End If
Next
ShowSubFolders Subfolder
Next
End Sub |
Partager