Q: Extract year from string row in file text and move torrent to relative folder reordered by year Question is tricky because is an evolution of my previously question.
To move torrent in folders I use this powershell script
$ToFolder = "$env:USERPROFILE\Desktop\to"
$FromFolder = "$env:USERPROFILE\Desktop\From"

#Create the sample folder on your desktop
#This line can be commented out if your ToFolder exists
New-Item $ToFolder -ItemType directory -Force

GCI -Path $FromFolder *.torrent | % {
    if ($_.Name -match "(19|20)\d{2}") {

        #Check to see if year folder already exists at the destination
        #If not then create a folder based on this year
        if (!(Test-Path "$ToFolder\$($Matches[0])")) {
            New-Item -Path "$ToFolder\$($Matches[0])" -ItemType directory
        }

        #Transfer the matching file to its new folder
        #Can be changed to Move-Item if happy with the results
        Move-Item -Path $_.FullName -Destination "$ToFolder\$($Matches[0])" -Force
    }
}

but in my NEW situation I must extract year from file text .txt
Example list of file .torrent inside a folder
Caccia Spietata.torrent
Caccia Zero terrore del Pacifico.torrent
Caccia.A.Ottobre.Rosso.torrent
Cacciatore Bianco Cuore Nero.torrent
Cacciatore di Ex.torrent
Cacciatori Di Zombie.torrent

Example of string list in file text
Caccia grossa a casa di Topolino (2006)
Caccia selvaggia [HD] (1981)
Caccia spietata (2006)
Cacciatori Di Zombie (2005)

What script must do ?
A. extract year from string in file text (every string is on a single row because file text is a list)
N.B script should compare between torrent files names and strings in file text list.
Caccia spietata (2006)

Extract year is possibile only for equal text or very very similar text like
Caccia Spietata.torrent
Caccia spietata (2006)

If I have
caccia.spietata.torrent
caccia SPiETata (2006)

this is for me very similar strings.
B. Make folder
2006

C. Move torrent
Caccia Spietata.torrent

into folder 2006
I want this solution because I have many .torrent file name without year so I must reorder them correctly by year.
Thanks for any help.

A: The first hurdle is parsing dates and names out of the string file. You then add them to a hash of movie name strings.
$movies = @()
(get-content C:\Path\Test4.txt) | foreach($_){
$properties = @{
date = $_.substring($_.IndexOf("(")+1,4)
name = $_.substring(0,$_.IndexOf("("))
}
$movies += New-Object PSObject -Property $properties
}
$movies

Once you have the movie names and dates separate, you loop through each movie and create a folder if it does not exist.
foreach($movie in $movies){
$movie.date
$datePath = "C:\Path\$($movie.date)"
if(-not(test-path $datePath)) {
new-item $datePath -ItemType "directory"
}

After that, you can split the name into key words based on whitespace.
$words = $movie.name -split '\s'
$words

Below is as far as I've gotten during a break of mine. The next step is a bit complicated seeming, as you have to then match the torrent files to the object in the hash based on keywords. It will be hard to construct such a filter without access to the raw data. My first thought would be to match based on fileName.torrent -like "*word*", but it looks like there are a ton of duplicate words. The next option is to match on multiple words, or maybe only use words that are not common (exclude "caccia", articles, etc). Either way, that should move you a bit closer to your goal. Maybe someone else can help finish, or I can revisit it during another break.
$movies = @()
(get-content C:\Path\Test4.txt) | foreach($_){
$properties = @{
date = $_.substring($_.IndexOf("(")+1,4)
name = $_.substring(0,$_.IndexOf("("))
}
$movies += New-Object PSObject -Property $properties
}
$movies

foreach($movie in $movies){
$movie.date
$datePath = "C:\Path\$($movie.date)"
if(-not(test-path $datePath)) {
new-item $datePath -ItemType "directory"
}
$words = $movie.name -split '\s'
$words
#this is as far as I got
}

UPDATE
I've added a bit that we talked about in comments. Most of the changes are at the bottom of the script.
$movies = @()
(get-content $Path\Test4.txt) | foreach($_){
$properties = @{
date = $_.substring($_.IndexOf("(")+1,4)
name = $_.substring(0,$_.IndexOf("("))
}
write-host $date
write-host $name

$movies += New-Object PSObject -Property $properties
}
#no significant changes were made above this point
$torrentFiles = dir $torrentPath

foreach($movie in $movies){
$datePath = "$Path\$($movie.date)"
if(-not(test-path $datePath)) {
new-item $datePath -ItemType "directory"
}
$words = ($movie.name -split '\s') | ?{ $_.Length -gt 1}
#this is as far as I got last time; most of the changes are below, though I did change 
#just a bit above

#this sets a number of words which needs to match. Currently, it has to match 
#on all words. If you wanted, you set it to a static number (2)
#     or do something like $words.count -1. There is a commented-out example of 
#such a solution.
$significant = $words.Count
#if($words.Count -eq 1){$significant = 1}
#else{$significant = ($words.Count - 1)

# here you loop through the torrentfiles, finding files whose base names have a 
#significant number of matching words with the string
 foreach($torrentFile in $torrentFiles){
 $matchingWords = 0
  foreach($word in $words){
   if($torrentFile.BaseName -match $word){
    $matchingWords += 1
   }
  }
  if($matchingWords -ge $significant){
  $_ | Move-Item -Destination $datePath
  }
 }
}

