posted on Wednesday, January 28, 2004 9:44 PM
by
demiliani
Retrieve informations about files and DLL
This is a routine that I've written and used today for a simple task: retrieve informations about files and DLL for a certain path on a machine. It seems working good.
using
System;using
System.Diagnostics;using
System.IO;namespace
InfoDLL {
// Get information about a file on the local machineclass FileGetInfo{
static void Main(){
FileVersionInfo fversinfo;
FileInfo finfo;
string filepath;//Declare an absolute path to a file to retrieve information aboutfilepath = "c:\\winnt\\system32\\wininet.dll";
//Ensure file existsif (File.Exists(filepath)){
//Get Version informationfversinfo = FileVersionInfo.GetVersionInfo(filepath);
//Print file descriptionConsole.WriteLine(fversinfo.FileDescription);
//Print full Path to fileConsole.WriteLine(
"\tfullpath : {0}",
fversinfo.FileName
);
//Print Major.Minor version infoConsole.WriteLine(
"\tversion : {0}.{1}",
fversinfo.FileMajorPart,
fversinfo.FileMinorPart
);
//Cleanupfversinfo =
null;
//Get general file informationsfinfo =
new FileInfo(filepath);//Get file attributesConsole.WriteLine(
"\tattributes: {0}",
finfo.Attributes.ToString()
);
//Get the size of the fileConsole.WriteLine(
"\tfile size : {0}k",
finfo.Length/1024
);
//Get the last time the file was written toConsole.WriteLine(
"\tlast write: {0}",
finfo.LastWriteTime.ToShortDateString()
);
//Cleanupfinfo =
null;}
}
}
}