Exporting a list of albums via .csv

I have a couple of hundred albums on various HDD's and I would like a script to export a csv file that lists all albums by artists like this:

Artist, Album, Genre, Year

I seem to be very close with this script...

$filename(csv,utf-16)Artist,Album,Genre,Year
$loop(%_folder%)%ARTIST%,%ALBUM%,%GENRE%,%YEAR%
$loopend()

however, instead of a list of albums I seem to get an entry for each track on the album
so I get multiple entries for the same album!

I know I'm close but I can't work out where I have gone wrong!
I have tried to search and follow various threads in the forum but don't seem to be able to nail it... Any help appreciated.

There is no variable called %_folder%
See the help on exports:
" $loop(%fieldname%) starts a new loop. The loop data is sorted by the fieldname."
So if you want to sort by ARTIST and then by ALBUM, it would require 2 loops to sort.
So I would think the export script would look like:
$loop(%artist%)$loop(%album%,1)%ARTIST%,%ALBUM%,%GENRE%,%YEAR%
$loopend()$loopend()

Hi ohrenkino
Many thanks for the fast reply! YES!! I finally got it to work with your alterations! Happily listing all my albums now.