i created one windows app by using c#.net and now one add one more form in that i wanted to get all the unused software or files by using c#.net
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Wim SturkenboomRank #2,527 · 554 reputationPosted Nov 20, 2014, 8:22 AM EST
Example code:
FileInfo fi = new FileInfo("yourfile.exe");
Console.WriteLine("Last access " + fi.LastAccessTime);
Embed it in a program that recursively loops through all directories, finds exe files and check the lastaccesstime.
Note:
You might have to run the below command in a command prompt with admin privileges to enable changes of the lastaccesstime on the NTFS filesystem
srikanth Radharam6 reputationPosted Nov 20, 2014, 7:02 PM EST
Wim SturkenboomRank #2,527 · 554 reputationPosted Nov 21, 2014, 12:37 AM EST
Below code does it slightly different, it loops through specified directories and add files older than a certain date to a datatable. The datatable needs to contain at least 2 columns for file name and last accessed date.
You can use the datatable as a data source for the list box.
///
/// traverse directory recursively and find 'old' files
///
/// directory
/// reference date
/// datatable to store file names and dates
///
private bool traverseDirectory(string strDirectory, DateTime dtReference, DataTable tblResults)
{
// find directories and process them
string[] directories = Directory.GetDirectories(strDirectory);
for (int cnt = 0; cnt < directories.Length; cnt++)
{
traverseDirectory(directories[cnt], dtReference, tblResults);
}
// find files and process them
string[] files = Directory.GetFiles(strDirectory, "*.exe");
for (int cnt=0; cnt < files.Length; cnt++)
{
DateTime lastaccesstime = File.GetLastAccessTime(files[cnt]);
if(lastaccesstime<=dtReference)
{
tblResults.Rows.Add(files[cnt], lastaccesstime);
}
}
return true;
}
Note: it's strongly advised to use a backgroundworker as it might be slow and the UI becomes unresponsive.