Results 1 to 9 of 9

Thread: Script to remove duplicate files

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    1

    Script to remove duplicate files

    Does anyone have any websites / references on a script that will search folders for duplicate files (same size and binary the same) and remove them? Thanks!

  2. #2
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    I would love to know the answer to this as well . . . still searching.
    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  3. #3
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Script to remove duplicate files

    Originally posted by EDenney
    Does anyone have any websites / references on a script that will search folders for duplicate files (same size and binary the same) and remove them? Thanks!
    Do you want to search for Size & Time only or do you have to check for the content aswell?

    If its simply size and time then i can put togher something using FSO.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  4. #4
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    Actually, I need to check the contents, too.
    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by mikeycorn
    Actually, I need to check the contents, too.
    Here you go. I found the code on the net, and slightly modified it.

    Hope this helps.

    VB Code:
    1. <%
    2. dim File1, File2
    3. dim Ret
    4.  
    5. File1="C:\DomainChecker.txt"
    6. File2="C:\DomainChecker2.txt"
    7.  
    8. Ret=FileCompare(File1, File2)
    9.  
    10. if Ret=true then
    11.     response.write "The two files are same"
    12. else
    13.     response.write "Two files are not the same"
    14. end if
    15.  
    16. Function FileCompare(fileA, fileB)
    17.     Const adTypeBinary = 1
    18.  
    19.     dim FSO
    20.     dim streamA
    21.     dim streamB
    22.  
    23.     set FSO = Server.CreateObject("Scripting.FileSystemObject")
    24.  
    25.     set streamA = Server.CreateObject("ADODB.Stream")
    26.     set streamB = Server.CreateObject("ADODB.Stream")
    27.  
    28.  
    29.     Dim sFileA, sFileB
    30.     Dim bMatched
    31.     Dim nSize
    32.     Dim bufA, bufB
    33.     Dim lengthA, lengthB
    34.  
    35.     FileCompare = Null
    36.  
    37.     If VarType(fileA) <> vbString Then
    38.         On Error Resume Next
    39.         sFileA = fileA.Path
    40.         If Err Then Exit Function
    41.         On Error GoTo 0
    42.     Else
    43.         If Not FSO.fileexists(fileA) Then
    44.             Exit Function
    45.         Else
    46.             sFileA = fileA
    47.         End If
    48.     End If
    49.  
    50.     If VarType(fileB) <> vbString Then
    51.         On Error Resume Next
    52.         sFileB = fileB.Path
    53.         If Err Then Exit Function
    54.         On Error GoTo 0
    55.     Else
    56.         If Not FSO.fileexists(fileB) Then
    57.             Exit Function
    58.         Else
    59.             sFileB = fileB
    60.         End If
    61.     End If
    62.  
    63.     streamA.Type = adTypeBinary
    64.     streamB.Type = adTypeBinary
    65.     streamA.open
    66.     streamB.open
    67.  
    68.     On Error Resume Next
    69.     streamA.loadfromfile sFileA
    70.  
    71.     If Err Then Exit Function
    72.  
    73.     streamB.loadfromfile sFileB
    74.     If Err Then Exit Function
    75.     On Error GoTo 0
    76.     bMatched = True
    77.     nSize = 2 ^ 15 '32K
    78.  
    79.     Do Until streamA.eos Or streamB.eos
    80.         bufA = streamA.read(nSize)
    81.         bufB = streamB.read(nSize)
    82.         lengthA = LenB(bufA)
    83.         lengthB = LenB(bufB)
    84.  
    85.         If lengthA <> lengthB Then
    86.             bMatched = False
    87.             Exit Do
    88.         ElseIf MidB(bufA, 1, lengthA) <> MidB(bufB, 1, lengthB) Then
    89.             bMatched = False
    90.             Exit Do
    91.         End If
    92.     Loop
    93.  
    94.     If Not (streamA.eos And streamB.eos) Then
    95.         bMatched = False
    96.     End If
    97.  
    98.     streamA.Close
    99.     streamB.Close
    100.     FileCompare = bMatched
    101. End Function
    102. %>
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  6. #6
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Script to remove duplicate files

    Originally posted by EDenney
    Does anyone have any websites / references on a script that will search folders for duplicate files (same size and binary the same) and remove them? Thanks!
    I assumed you can use FSO to iterate through folder and pass file name to the function i passed, if not check out my other post on FSO on this forum. If you still have problems then let me know i will try to put together a more detailed example.

    Hope this helps.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  7. #7
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    How much kinder could you be? Thanks a bunch!
    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  8. #8
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by mikeycorn
    How much kinder could you be? Thanks a bunch!
    So I take it that this was what you were looking for.

    Glad to help
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  9. #9
    Registered User
    Join Date
    Jan 2013
    Posts
    1

    Re: Script to remove duplicate files

    To find and remove duplicate files, a program from DuplicateFilesDeleter.com works well for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width