Click here to Skip to main content
13,353,706 members (64,089 online)
Click here to Skip to main content
Add your own
alternative version


76 bookmarked
Posted 4 Aug 2003

Backup Utility in C#

, 4 Aug 2003
Rate this:
Please Sign up or sign in to vote.
A utility to backup directories and stick a datestamp on the folder, and remove folders older than N days, where N is configurable.

Sample Image - backup.gif


During a development project, I realized I needed something to backup my solutions every night, and be tagged with a date stamp. I looked around the Net for some DOS utilities but none really fitted the bill as far as what I was looking for. Eventually, I decided to just code it. Turned out to be super simple in C#.


My goal was to backup my solution from a source folder (e.g. C:\Data) to a backup folder (e.g. C:\Backup\Data_080403). I also wanted to only keep N number of days of backups and not let my backup folder grow infinitely. So, for instance, I wanted to keep 30 days worth of backups at most. So, whenever, any files older than 30 days were discovered, I wanted the system to delete them automatically.


I used the System.IO's Directory and DirectoryInfo classes to create folders, delete folders, and wrote a method to recursively copy folders from one location to the next. I utilized the DirectoryInfo class to figure out how old a given folder was, in order to delete it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralNice. Yet it doesn't work twice on the same day Pin
Yaron Dan-Goor21-Mar-11 7:50
memberYaron Dan-Goor21-Mar-11 7:50 
GeneralUse Path.DirectorySeparatorChar Pin
codekamfung15-Apr-04 0:13
membercodekamfung15-Apr-04 0:13 
GeneralRe: Use Path.DirectorySeparatorChar Pin
Anonymous8-Oct-04 10:02
sussAnonymous8-Oct-04 10:02 
GeneralRe: Use Path.DirectorySeparatorChar Pin
justsml12-Dec-04 11:34
memberjustsml12-Dec-04 11:34 
GeneralPVCS systems Pin
Håkan Nilsson6-Aug-03 5:48
memberHåkan Nilsson6-Aug-03 5:48 
GeneralRe: PVCS systems Pin
M C15-Jul-10 11:00
memberM C15-Jul-10 11:00 
GeneralSuggestions Pin
Gunmen6-Aug-03 0:13
memberGunmen6-Aug-03 0:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 5 Aug 2003
Article Copyright 2003 by rbala
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid