How do I delete files by ‘partial filenames’?

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
Debugger
Posts: 630
Joined: Thu Jan 26, 2017 11:56 am

How do I delete files by ‘partial filenames’?

Post by Debugger »

How do I delete 600 files by ‘partial filenames’?


I copied the 600 names on separate lines and added them to Everything - doesn't work!

So, I will never, ever succeed in finding and removing duplicates! This is a failure! Why can't any tools do this, I don't want to forever have duplicates on my disk, and a waste of disk space!

Manually removing duplicates to entertain for 1 years.

I have tested 100 scripts (various and modified) and not even one partial file name is found.

This is the most complicated task in the whole world that does not even find one name.

The more elaborate and complicated scripts and even debugging, it finds nothing.

So I have to 6,000 names manually compare, but no sense, for several years combine so many methods and not even one partial name does not find 1 filename.

Example Powershell
# Ustal ścieżkę do katalogu, w którym chcesz wyszukiwać pliki
$searchPath = "G:\【M独家】"

# Ścieżka do pliku wynikowego
$outputFile = "I:\wyniki.txt"

# Wczytaj fragmenty z pliku tekstowego
$fragments = Get-Content -Path "I:\fragments.txt"

# Tworzymy nowy plik wynikowy lub czyścimy go, jeśli już istnieje
Clear-Content -Path $outputFile -ErrorAction SilentlyContinue

# Przetwarzamy pliki w zadanym katalogu
Get-ChildItem -Path $searchPath -Recurse -File | ForEach-Object {
$file = $_

# Sprawdzamy, czy nazwa pliku zawiera którykolwiek z fragmentów
foreach ($fragment in $fragments) {
if ($file.Name -like "*$fragment*") {
# Jeśli plik pasuje, dodajemy jego pełną ścieżkę do pliku wynikowego
$file.FullName | Out-File -FilePath $outputFile -Append -Encoding UTF8
break # Przerywamy, aby nie zapisywać tego samego pliku wielokrotnie
}
}
}

Write-Host "Wyniki zostały zapisane w pliku: $outputFile"
horst.epp
Posts: 1448
Joined: Fri Apr 04, 2014 3:24 pm

Re: How do I delete files by ‘partial filenames’?

Post by horst.epp »

Debugger wrote: Wed Nov 06, 2024 10:46 am So, I will never, ever succeed in finding and removing duplicates! This is a failure! Why can't any tools do this, I don't want to forever have duplicates on my disk, and a waste of disk space!
Failures are defined if a tool doesn't have a function as described.
I don't see that your request of removing duplicates is part of a search tool at all.
Such features are provided in several file managers (Everything is not a file manager)
which even integrate Everything for the search part of the job.

David may provide a solution using Everything functions in the best way.
Debugger
Posts: 630
Joined: Thu Jan 26, 2017 11:56 am

Re: How do I delete files by ‘partial filenames’?

Post by Debugger »

But Everything does not support the search for more than one ‘partial name’.

Or a problem with the number of characters because it is not displayed:

97 571 characters

I am trying yet another method of searching by duplicate names (duplicate strings), but my script is not returning any duplicates. Where is the error in the script?

I have already tested various 1000 scripts today (12 hours of work), and I still can't find anything.

# Ścieżki do plików
file1_path = r"I:\FOLDER\plik1.txt"
file2_path = r"I:\FOLDER\plik2.txt"
output_file_path = r"I:\FOLDER\plik3.txt"

# Wczytanie plików w UTF-8
with open(file1_path, 'r', encoding='utf-8') as file1:
file1_lines = file1.read().splitlines() # Wczytanie pliku do listy linii

with open(file2_path, 'r', encoding='utf-8') as file2:
file2_lines = file2.read().splitlines()

# Wykrywanie duplikatów (linia, która występuje dokładnie w obu plikach)
duplicates = [line for line in file1_lines if line in file2_lines]

# Zapis duplikatów do pliku wyjściowego
with open(output_file_path, 'w', encoding='utf-8') as output_file:
for line in duplicates:
output_file.write(line + "\n")

print(f"Duplikaty zostały zapisane do: {output_file_path}")



# Ścieżki do plików
plik1_sciezka = r"I:\FOLDER\plik1.txt"
plik2_sciezka = r"I:\FOLDER\plik2.txt"
plik3_sciezka = r"I:\FOLDER\plik3.txt"

# Funkcja do wczytania pliku i usunięcia zbędnych białych znaków
def wczytaj_plik(sciezka):
with open(sciezka, 'r', encoding='utf-8') as plik:
# Wczytaj linie, usuń białe znaki i zwróć listę
return [linia.strip() for linia in plik.read().splitlines()]

# Wczytanie plików w UTF-8
plik1_linie = wczytaj_plik(plik1_sciezka)
plik2_linie = wczytaj_plik(plik2_sciezka)

# Porównanie plików i wykrywanie dokładnych duplikatów (linia, która występuje dokładnie w obu plikach)
duplikaty = [linia for linia in plik1_linie if linia in plik2_linie]

# Zapis duplikatów do pliku wyjściowego
with open(plik3_sciezka, 'w', encoding='utf-8') as plik_wyjsciowy:
for linia in duplikaty:
plik_wyjsciowy.write(linia + "\n")

print(f"Duplikaty zostały zapisane do: {plik3_sciezka}")
void
Developer
Posts: 16771
Joined: Fri Oct 16, 2009 11:31 pm

Re: How do I delete files by ‘partial filenames’?

Post by void »

To search partial names in your file list, add a * prefix and suffix.

For example:

partial search
=>
*partial search*



If you do not want to match spaces, replace spaces with a *

For example:

*partial search*
=>
*partial*search*



Replace ** with a single * to avoid matching the full path and name.

For example:

*partial search*
=>
*partial**search*
=>
*partial*search*
Post Reply