PC Review


Reply
Thread Tools Rate Thread

delete old files

 
 
Matt
Guest
Posts: n/a
 
      21st Nov 2007
I have several folders on a server that contains files that go back 3-4 years. It was mentioned that keeping files that long is no longer needed. So my question is, is there a way to create a windows service in C# that can delete files in the folders that are older then 12 months?

The server is structured something like this:

DataLogs
Server1
App1 - this folder contains all the log files

or it can look something like this:
DataLogs
Server1
App1
Logs - the log files can be stored here


and another example:
DataLogs
App1 - logs stored here.


So is there a way to do a 'high level' search and delete all files that are older then 12 months or do I have to go through every folder and look? How would that be accomplished?

 
Reply With Quote
 
 
 
 
zacks@construction-imaging.com
Guest
Posts: n/a
 
      21st Nov 2007
On Nov 21, 9:33 am, "Matt" <M...@community.nospam.com> wrote:
> I have several folders on a server that contains files that go back 3-4 years. It was mentioned that keeping files that long is no longer needed. So my question is, is there a way to create a windows service in C# that can delete files in the folders that are older then 12 months?


Yes.

> So is there a way to do a 'high level' search and delete all files that are older then 12 months or do I have to go through every folder and look? How would that be accomplished?


You first need to figure out how to design a Windows Service
with .NET. There is plenty of help, in fact there is a Walkthrough
with step by step instructions on how to create a Windows Service
project in VS2005.

Once you have a service that starts up at boot time, and wakes up on
some predetermined interval and is ready to do some work, then you
need to give it some work to do. In you case, you want to do a
directory scan using the Directory Class to get a list of all files
and folders from a specified root. The loop through the files and
determine the creation date using the FileInfo class. Delete the
selected files with the File class.

Sounds like a fun project.
 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      21st Nov 2007
I think it would be overkill to have a Windows Service running 24hrs a day
taking up resources just to delete old files periodically. You would be
better served with a Console EXE that does the same thing and goes away when
it is done. You would simply have this run once a week (or whatever) under
Task Scheduler.

It should be easy to find recursive directory traversal code that will
delete all files (with whatever extension(s) ) that have a lastmodifieddate
of a certain value or older.

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



"Matt" wrote:

> I have several folders on a server that contains files that go back 3-4 years. It was mentioned that keeping files that long is no longer needed. So my question is, is there a way to create a windows service in C# that can delete files in the folders that are older then 12 months?
>
> The server is structured something like this:
>
> DataLogs
> Server1
> App1 - this folder contains all the log files
>
> or it can look something like this:
> DataLogs
> Server1
> App1
> Logs - the log files can be stored here
>
>
> and another example:
> DataLogs
> App1 - logs stored here.
>
>
> So is there a way to do a 'high level' search and delete all files that are older then 12 months or do I have to go through every folder and look? How would that be accomplished?
>

 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      21st Nov 2007
its going to be scheduled to run the 30th of every month so its not running
24 hours a day every day. I was thinking a service at first but the more I
thought about it, I'll create a console app with no user interaction
required and just have it scheduled.

"Peter Bromberg [C# MVP]" <(E-Mail Removed)> wrote in message
news:F6D19865-21F6-4213-AFF3-(E-Mail Removed)...
>I think it would be overkill to have a Windows Service running 24hrs a day
> taking up resources just to delete old files periodically. You would be
> better served with a Console EXE that does the same thing and goes away
> when
> it is done. You would simply have this run once a week (or whatever) under
> Task Scheduler.
>
> It should be easy to find recursive directory traversal code that will
> delete all files (with whatever extension(s) ) that have a
> lastmodifieddate
> of a certain value or older.
>
> --Peter
> "Inside every large program, there is a small program trying to get out."
> http://www.eggheadcafe.com
> http://petesbloggerama.blogspot.com
> http://www.blogmetafinder.com
>
>
>
> "Matt" wrote:
>
>> I have several folders on a server that contains files that go back 3-4
>> years. It was mentioned that keeping files that long is no longer needed.
>> So my question is, is there a way to create a windows service in C# that
>> can delete files in the folders that are older then 12 months?
>>
>> The server is structured something like this:
>>
>> DataLogs
>> Server1
>> App1 - this folder contains all the log files
>>
>> or it can look something like this:
>> DataLogs
>> Server1
>> App1
>> Logs - the log files can be stored here
>>
>>
>> and another example:
>> DataLogs
>> App1 - logs stored here.
>>
>>
>> So is there a way to do a 'high level' search and delete all files that
>> are older then 12 months or do I have to go through every folder and
>> look? How would that be accomplished?
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shift+delete doesn't delete files in outlook .inbox stalled peteraylmore Microsoft Outlook Discussion 1 28th Apr 2008 11:28 PM
Special permissions - Delete and Delete Files and Folders Paul Dunn Microsoft Windows 2000 0 2nd May 2006 08:02 PM
NTFS permission to delete files, but not delete or move folders =?Utf-8?B?R29yZG9u?= Microsoft Windows 2000 File System 0 11th Feb 2005 03:37 PM
Word 2003 - XP Home - delete not delete - files come back Xylophone Microsoft Word Document Management 10 24th Sep 2004 02:17 PM
Cannot follow link to open new window after Delete Cookies, Delete Files. Riaan Windows XP Internet Explorer 2 8th Apr 2004 01:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:10 AM.