Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3666360
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:52:15+00:00 2026-05-19T01:52:15+00:00

I have a directory with several thousand text files that I need to process.

  • 0

I have a directory with several thousand text files that I need to process. Some of these files are identical while others are identical except the timestamp varies by a few seconds / milliseconds. I need some way to automate the deletion of identical files and only keep one copy.

I’m thinking of something like:

while there are files in the directory still
{
    get file                    // e.g., file0001

    while (file == file + 1)    // e.g., file0001 == file0002 using 'fc' command
    {
        delete file + 1
    }

    move file to another directory
}

Is something like this even possible in Microsoft Windows Server 2003’s DOS?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:52:16+00:00Added an answer on May 19, 2026 at 1:52 am

    Of course it is. Everything is possible in batch. 😀

    This batch doesn’t actually delete files. It just echos the result of the comparison. You can delete either one of the files if you find two that are the same.

    Save the code as CleanDuplicates.bat and start the program with CleanDuplicates {Folder}

    Provided AS IS, without any guarantees! I don’t want you knocking on my door because your entire server is messed up. 😉

    The code actually calls itself recursively. This could maybe be done in a different way but hey, it works. It also starts itself again in a new cmd, because that makes cleaning up easier. I tested the script in Windows Vista Business, but it should work on Server 2003 as well. Hey, it even has a help function. 😉
    It contains two loops that each return every file, so when you implement the actual deleting, it may report that some files don’t exist, because they are deleted in an earlier iteration.

    @echo off
    rem Check input. //, /// and //// are special parameters. No parameter -> help.
    if %1check==//check goto innerloop
    if %1check==///check goto compare
    if %1check==////check goto shell
    if %1check==/hcheck goto help
    if %1check==check goto help
    
    rem Start ourselves within a new cmd shell. This will automatically return to
    rem the original directory, and clear our helper environment vars.
    cmd /c %0 //// %1
    echo Exiting
    goto end
    
    :shell
    rem Save the current folder, jump to target folder and set some helper vars
    set FCOrgFolder=%CD%
    cd %2
    set FCStartPath=%0
    if not exist %FCStartPath% set FCStartPath=%FCOrgFolder%\%0
    
    rem Outer loop. Get each file and call ourselves with the first special parameter.
    for %%a in (*.*) do call %FCStartPath% // "%2" "%%a"
    
    goto end
    
    :innerloop
    rem Get each file again and call ourselves again with the second special parameter.
    for %%b in (*.*) do call %FCStartPath% /// %2 %3 "%%b"
    goto end
    
    :compare
    rem Actual compare and some verbose.
    if %3==%4 goto end
    echo Comparing
    echo * %3
    echo * %4
    
    fc %3 %4 >nul
    
    rem Get results
    if errorlevel 2 goto notexists
    if errorlevel 1 goto different
    
    echo Files are identical
    goto end
    
    :different
    echo Files differ
    goto end
    
    :notexists
    echo File does not exist
    goto end
    
    :help
    
    echo Compares files within a directory.
    echo Usage: %0 {directory}
    goto end
    
    :end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have several .NET applications that monitor a directory for new files, using FileSystemWatcher.
I have a directory with PDF files that I need to create an index
I have several thousand ebooks that need to be organized on a headless linux
I have a directory with several subdirectories with files. How can I copy all
I have a directory full of files and I need to pull the headers
I have a directory of files that I'd like to append file extension to
I have my sources split up in several directories, so for each directory I
I have a directory of bitmaps that are all of the same dimension. I
I have a directory with 500,000 files in it. I would like to access
I have a directory full (~10 3 , 10 4 ) of XML files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.