.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

delete specific file from folder in vb dot net

Posted By: Ajesh Rawat     Posted Date: April 15, 2010    Points:2   Category :Windows Application
Dear All I want to delete the name starting from q form a folder
I have a folder temp.
Inside this folder lots of file but i want to delete all the file whose name start form tmp_doc
and date of creation graterthan 2 days.

Author: Venkat             
Posted Date: April 15, 2010     Points: 5   


Here is the function based on your requirment to delete file of spefcific name start and should be created 2days before

private void DeleteFiles()
string [] myFiles = Directory.GetFiles(@"c:\Temp","tmp_doc*");

foreach (string fileToDelete in myFiles)
FileInfo fileInformation = new FileInfo(fileToDelete);

if (fileInformation.CreationTime.AddDays(2) >= DateTime.Now.AddDays(0))

I didn't check the code because I do not want to delete the file older than 2 days in my system..:). Hope this will work.

And yes you can convert this code in vb.net using online conversion tool

Mark As Answer if this solve your problem
Warm Regards,

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend