I haven't tested Xander Bakker 's code, but here it is formatted (the old forum conversion scrambled some scripts)
import arcpy, os
ws = r'C:\Project\_Forums\Viewshed\test.gdb'
arcpy.env.workspace = ws
rasters = arcpy.ListRasters("*")
for raster in rasters:
rasloc = ws + os.sep + raster
fields = "*"
try:
lstFlds = arcpy.ListFields(rasloc)
header = ''
for fld in lstFlds:
header += ",{0}".format(fld.name)
if len(lstFlds) != 0:
outCSV = outPath + os.sep + raster + outExt
f = open(outCSV,'w')
header = header[1:] + ',RasterName\n'
f.write(header)
with arcpy.da.SearchCursor(rasloc, fields) as cursor:
for row in cursor:
f.write(str(row).replace("(","").replace(")","") + "," + raster + '\n')
f.close()
except:
print raster + " - is not integer or has no attribute table"
del row
If you are just getting into ArcGIS, you should look into Python (if you don't already know it) since that is the scripting language many of us use. Key about python, indentation is very important. Good luck.