Click here to Skip to main content
14,741,306 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
how to get all junk files in the list view and delete all the files in c#.net
i create one form with list view now i wanted to get all the junk files in that listview and then delete them
Posted
Updated 17-Nov-14 1:52am
v2
Comments
Thanks7872 17-Nov-14 7:27am
   
And? What have you tried so far? Where is the code you have implemented? What is the issue doing the same?

Remember, we are here to help/answer the question.
Srikanth59 17-Nov-14 23:46pm
   
private void delete_load (object sender, EventArgs e)
{
DirectoryInfo Dir = new DirectoryInfo(System.IO.Path.GetTempPath());

FileInfo[] Files = Dir.GetFiles();

foreach (FileInfo file in Files)
{
listView1.Items.Add(file.Name);
}
}
this is the code i got it now i wanted to get all the junk files in the listview and then delete all that files from listview
Dave Kreskowiak 17-Nov-14 7:28am
   
...and your definition of a "junk file" is what?
Srikanth59 17-Nov-14 8:24am
   
junk files means temp files in system
Dave Kreskowiak 17-Nov-14 11:54am
   
That's not a sufficient definition.

"temp file in system" can mean anything and not all "temp files" have the same extension, so how are you going to determine what is a "temp file" and what isn't??
Srikanth59 17-Nov-14 7:51am
   
i would like get the windows temp files in the listview
and then delete all files
Dusara Maulik 17-Nov-14 9:52am
   

1 solution

try this code sample to dispaly temp file in listview

private void Form3_Load(object sender, EventArgs e)
        {
            DirectoryInfo Dir = new DirectoryInfo(System.IO.Path.GetTempPath());

            FileInfo[] Files = Dir.GetFiles();

            foreach (FileInfo file in Files)
            {
                listView1.Items.Add(file.Name);
            }
        }
   
Comments
Srikanth59 17-Nov-14 7:45am
   
it works the code but i would like get the windows temp files in the listview
and then delete all files
Kiran Wilson 17-Nov-14 7:50am
   
I didn't get you..

can you please clarify your need..
Srikanth59 17-Nov-14 7:59am
   
i created one windows application in c#.net now i need to get all the temp files of the system in the listview and then delete all that files
Kiran Wilson 17-Nov-14 8:04am
   
I hope you are getting all temp files from my earlier sample?
you can use the same loop to delete all the files in a button click..
I hope that is the working structure of your application.
Srikanth59 17-Nov-14 8:17am
   
thank you yes it got all the files

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900