How do I make a script like this in the command line?

Bence Varga 0 Reputation points
2023-02-11T15:31:23.3933333+00:00

I would like to create a script that lists every files, which first four characters of the filename match/similar. I would need this because I have hundreds of files and I don't want to delete the duplicated files manually. Somebody suggested me to write a script to the command line. But unfortunately I can't programming. :(

e.g.

xyzvw.txt

xyzvq.txt

qwerty.txt

qwertz.txt

So xyzvw.txt and xyzvq.txt are have the same first four character. I want to find every files like these.

I also tried duplicator deleter programs, but it only deleted a few duplication.

Can anyone help?

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,874 questions
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 35,626 Reputation points
    2023-02-12T13:50:09.0733333+00:00

    Is this what you are looking for?

    $folder = 'C:\temp\'
    $First4 = Get-ChildItem $folder -file | foreach { $_.Name.Substring(0,4)} | Select-Object -Unique
    "Here are the unique prefixes that we found."
    $First4
    
    foreach ($four in $First4) {
        ""
        "--------- $four -----------"
        (Get-ChildItem $folder -Filter ($four + "*")).fullname
    }    
    

  2. Bence Varga 0 Reputation points
    2023-02-15T17:30:39.4066667+00:00

    I found a program, which you can find similar files and very easy to use.

    Anti-Twin

    https://antitwin.org/en/download.html

    Thank you for your helping!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.