Click here to Skip to main content
15,885,365 members
Articles / Desktop Programming / Win32
Article

CD Burner - console version

Rate me:
Please Sign up or sign in to vote.
2.72/5 (8 votes)
4 Jul 2008CPOL5 min read 28.9K   1.1K   14   3
A command-line program that backs up folders and files specified in a text file to CD-W

Invoking CDBackup passing CopyArguments.arg, the program writes Adding file names...Adding file contents...Done, then exits

Introduction

The first program described in this article, CDBackup, creates a CD-W disk containing folder trees of the files specified in a control file listed on the command line.

Background

The CDBackup application is a direct expansion of the ideas presented in the CodeProject article CD Burner, By Akin Ocal.

Using the Code

At my house, we store backups of the important data on our computers, recorded on CD-W, in our bank safe deposit box. Manually selecting files and folders to be backed up was error-prone. The CDBackup program allows me to create and maintain a list of the files and folders to be written to the CD-W. This list file is fed to the CDBackup application on the command line. I create a shortcut on the desktop that invokes the program, passing the list file, and backups consist of putting a blank CD in the drive and clicking on the icon (or they would, except...but I'll talk about that later).

The list file that contains the specification of the files to copy to the CD-W has a certain format. Comments are allowed. Three forms of comments are supported. The forms are copied from the C language, the C++ language, and the DOS batch file 'language'.

  • A comment can start with /* and end with */ and can extend across lines (or not) (C style).
  • A comment can start with // and ends at the end of the current line (C++ style).
  • A comment can start with :: and ends at the end of the current line (DOS batch style).

Mostly, I wanted to back up every file in every folder below a certain point. But there were a few files that I wanted to copy individually. So there are two actual copy commands.

Copy pattern source destination
RecursiveCopy pattern source destination

For example, to copy the file D:\Utils\MakeList to the root of the CD-W, the command would be:

Copy MakeList "D:\Utils" \

To copy all of D:\Projects\Templates\FileOpenDialog\MultiSelect to a folder Templates\FileOpenDialog\MultiSelect on the CD-W, the command would be:

RecursiveCopy *.* "D:\Projects\Templates\FileOpenDialog\MultiSelect" 
                  "Templates\FileOpenDialog\MultiSelect"

A complete argument file might look like:

/* This
is
a comment */

// This is a comment

:: This is a comment


Copy MakeList "D:\Utils" \
RecursiveCopy *.* "D:\Projects\Templates\FileOpenDialog\MultiSelect" 
                  "Templates\FileOpenDialog\MultiSelect"

Points of Interest

In my haste to get things working, I blew past a nit that turned out to burn me. That nit is that StgCreateDocfile (used in the article CD Burner, By Akin Ocal, from which I started) creates a structured storage with a limit of 31 character file names. Once the program was up and running, I found that we wanted to back up a large number of files whose names exceeded 31 characters in length. So I wound up abandoning this project.

If you look up StgCreateDocfile in MSDN or other Microsoft documentation, you will find (at least I found) the following:

"Note All Microsoft® Windows® 2000 and Windows XP applications should use the new function, StgCreateStorageEx, instead of StgCreateDocfile."

I tried using StgCreateStorageEx, but had various problems, and gave up, because I believe I have found a simpler way of performing backups.

In my frantic Googling to find a solution to the 31-character limit imposed by StgCreateDocfile, I happened to find a reference to the location of the cache where WindowsXP queues files destined for writing to a CD-W. The location is:

drive-letter:\Documents and Settings\username\Local Settings\
                   Application Data\Microsoft\CD Burning

I realized all I needed was the first part of CDBackup - the part that marshaled the files to be written to CD. I named the new version CDQueueForBackup.

I replaced the code that put each file in structured storage with code that instead copied the file to the appropriate location in a tree below drive-letter:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning, and I was almost home free.

Turns out when Microsoft decided to create a CD format (Joliet) on top of the basic CD data format available at the time (ISO 9660), Microsoft decided to limit file names on a CD to 64 characters. At least a 64-character limit is better than the 31-character limit imposed by my first implementation.

So I added a check for files whose names exceeded 64 characters in length, and I was done.

Now the sequence is:

  • Click the backup icon.
  • The backup icon runs CDQueueForBackup with the list file as command-line parameter.
  • CDQueueForBackup copies the specified files below drive-letter:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning, creating any required folders.
  • If the name of any file exceeds 64 characters in length, CDQueueForBackup shows the path and file name.

CDQueueForBackup lists files whose names exceed 64 characters in length

(CDQueueForBackup's diagnostic output is much easier to read if the DOS box's window is set to display more columns. To satisfy CodeProject formatting, I was forced to reduce the width of the DOS box display when I took the screen shot shown above.)

The user is then free either to use the built-in capabilities of WindowsXP to burn a CD (choose 'Write these files to CD' from the context menu) or clean up the queue without burning (choose 'Delete temporary files' from the context menu).

The context menu for the CD drive allows 'Write these files to CD' and 'Delete temporary files' options

Since only we at home use this program, I didn't worry about an elegant method of dealing with too-long file names. When we ran the program the first time, the program listed four files that were too long. We simply renamed the files, cleaned up the queue, reran CDQueueForBackup, and burned the first CD. Next time (unless we create another problem file in the mean time), there should be no problem.

CDQueueForBackup displays a dot (period) for every file it queues

CDQueueForBackup displays a dot for every file queued.

Windows XP displays a baloon alert when files are copied to the CD Queue location

The above balloon alert is displayed when Windows XP detects that files are being copied to the CD burn queue area.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralLooks like you pasted into the wrong view Pin
Christian Graus5-Jul-08 3:59
protectorChristian Graus5-Jul-08 3:59 
GeneralRe: Looks like you pasted into the wrong view Pin
Leslie Sanford5-Jul-08 8:48
Leslie Sanford5-Jul-08 8:48 
GeneralRe: Looks like you pasted into the wrong view Pin
2b|!2b==?5-Jul-08 18:18
2b|!2b==?5-Jul-08 18:18 

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.