You are trying to capture the username from the subdomain and a filename, too. No problem.
IMHO, you should NOT attempt to redirect to the main domain but the subdomain should be pointed at the main domain (SHARED DocumentRoot) and allow mod_rewrite to fetch the subdomain’s folder (because it makes your redirections easier when the URL does not change).
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\\.mysite\\.com$
RewriteCond %{HTTP_HOST} ^([a-z]+)\\.mysite\\.com [NC]
# NOTA BENE: The subdomain and folder must be lowercase!
RewriteRule ^$ folder.php?foldername=%1 [L]
RewriteCond %{HTTP_HOST} !^www\\.mysite\\.com$
RewriteCond %{HTTP_HOST} ^([a-z]+)\\.mysite\\.com [NC]
# again, the subdomain and folder must be lowercase!
RewriteRule ^([a-z./]+)$ folder.php?foldername=%2&link=$1 [L]
# I added a key name of "link" for $1 to enable it to be accessed properly
# the path/filename must be lowercase letters only (with / and . as appropriate)
It’s NOT rocket science but a simple subset of regular expressions applied to simple Apache variables. Have a look at the tutorial linked in my signature for more information.