Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A script to find duplicate files please...

Status
Not open for further replies.

Molenski

IS-IT--Management
Jan 24, 2002
288
DE
Does anybody know of a script that will find and list duplicate file names along with their sizes and sub directories? We have a server on our network and I know that there is a lot of work being duplicated and saved and need to get rid of it. Can somebody help me please? Ta!
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi there. Ta for getting back.

Unfortunately, the only coding I did was some very basic web pages a few years ago so to be very honest, I've not attempted; this really isn't because I'm lazy, it's just that I wouldn't know where to start! I've tried the internet but not found anything exactly right. If you would be prepared to give me a few tips, I'd love to have a go myself?

Cheers.
 
Hi again. I've found the following:

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strStartFolder = "C:\Adam"

Set objFolder = objFSO.GetFolder(strStartFolder)

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(strStartFolder)

For Each strKey in objDictionary.Keys
strFileName = strKey
If InStr(objDictionary.Item(strFileName), ";") Then
arrPaths = Split(objDictionary.Item(strFileName), ";")
Wscript.Echo strFileName
For Each strFilePath in arrPaths
Wscript.Echo strFilePath
Next
Wscript.Echo
End If
Next

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

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

To be honest, I'm not sure how it works but it outputs file names to alert boxes. Do you know what I'd have to change to output that to a text file along with the sizes of the files to make sure they are exactly the same?

Thanks for your help on this and if I'm coming across as a complete coding thicky...that's 'cos I am!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top