Below query is used to get Apex Classes names in Salefsforce.
SOQL:
SELECT Name, Body FROM ApexClass
One more approach is use Ant tool to fetch all Apex Classes with the below Package.xml.
<types>
<members>*</members>
<name>ApexClass</name>
</types>
To get the names of the retrieved Apex Classes, use the below link
https://www.infallibletechie.com/2014/10/how-to-copy-all-files-names-from-folder.html
Cheers!!!