When there is a situation in Windows, there has to be some solution using PowerShell. So Once again I’ve something useful for you.

SITUATION:

A folder in my Hard disk has about 300 movies and I want to share this list of movie names with my friend, or I want to compare my list with one of my friend’s collection of movies on his hard disk.

SOLUTION:

Below script will work in above situation, you just need to change few parameters in the script:


$list = Get-ChildItem -Path 'D:\Movies\' -Recurse | `
Where-Object { $_.PSIsContainer -eq $false -and $_.Extension -ne '.srt' }
write-host "`nTotal : "$list.Count "movies `n"
ForEach($n in $list){
$n.Name | Out-File -Append 'D:\Movielist.txt'
}
view raw

Filename.ps1

hosted with ❤ by GitHub

First highlighted parameter is the Directory of the folder, where you want the script to search for movie files, and the second highlighted one is the location of the output file to be placed with name Movielist.txt like below.

File list captured with PowerShell

If you want to compare two folders for files that aren’t common, for example – I want to compare movies in my laptop with movies in my friends Hard Disk, just add the following script in the above script and modify the highlighted location with the directory to be compared.


$list2 = Get-ChildItem 'F:\FolderInFriendsHDD\'|`
Where-Object {$_.PSIsContainer -eq $false -and $_.Extension -ne '.srt'}
Compare-Object -ReferenceObject $list -DifferenceObject $list2 -IncludeEqual

Your output will look something like this :

Comparing Files with PowerShell

Happy Learning! 🙂

signature