Enumerating GAC Assemblies with IronPython

posted @ Sunday, October 31, 2004 1:35 PM

 

I haven't been able to play with IronPython for a while now, work has been rather busy and I have also just received a copy of Programming .NET Security from the folks at O'Reilly to read and review. So far I am rather impressed with the book. This morning when I woke up I decided to sit down and play around with IronPython again. I love the fact that I can simple write a script yet have the power of the .NET Framework available to me at the same time. With the following script we can enumerate all of the assemblies installed within the GAC (Global Assembly Cache).

 

from System import *
from System.IO import *
from System.Diagnostics import *
def EnumAssemblies(di):
dia = di.GetDirectories()
if dia != None:
for d in dia:
EnumAssemblies(d)
fia = d.GetFiles("*.dll")
if fia != None:
for file in fia:
version = FileVersionInfo.GetVersionInfo(file.FullName)
print String.Format("{0}, {1}", file.Name, version.FileVersion)
path = Environment.ExpandEnvironmentVariables("%WINDIR%")
path += "\\assembly\\gac"
di = DirectoryInfo(path)
EnumAssemblies(di)