There are several errors in your code.
First, a file geodatabase is a directory, not a file, so you'll want to iterate over the directories, not the files. Second,
arcpy.ListWorkspaces lists workspaces in the current directory, not the directory you are iterating over in your loop. Also, it is unnecessary as the arcpy.Compact_management will accept paths as string. (It does weed out any possible directories with ".gdb" in the that might not be geodatabases.) Finally, pay attention to your indenting, as this is very important to the python interpreter to separate blocks of code. Always indent after a colon (:) Try the following:
import arcpy, os
from arcpy import env
arcpy.env.workspace = r"C:/"
for path, dirs, files in os.walk(arcpy.env.workspace):
for dir in dirs:
if ".gdb" in dir:
workspace = print os.path.join(path, dir)
To test, you could substitute
print workspace for the call to
arcpy.Compact_management, just to make sure you are hitting all the geodatabases you expect.