Back up files to cdr (problem is how do i sort dir larger then 700megs) for multi cdr listing

I'm trying to sort a back up of files in a directory, and my problem is trying to sort the files so i can make multiple cdr iso's from one directory and the original directory is larger then 700 megs( a normal cdr image)

ive found routines to read the files, but im having problems with getting the max amount of space i can to burn a cdr from the directory.

basically I'm trying to read the file list of a given directory then sort the files to fit the maximum files i can onto cdr images.

I'm not including code in this so i can see if I'm reading the files correctly, i was thinking there is maybe a way to do this list as it reads them.
all im looking for is a list of files ie disk 1 [file listing] disk 2 [file listing] etc etc

please ask for any other info you may need.

Thank you in advance for any code and help you may provide

Im using 2008 pro for this project.
Who is Participating?
Here's an example using VB6 logic.  The logic utilizes a class to contain the information about each file, and it uses a collection to create a sorted list of file names.
'Code for the Class clsFileData
Option Explicit
Private m_FileName As String
Private m_FileSize As Double
Private Sub Class_Initialize()
    m_FileName = ""
    m_FileSize = 0#
End Sub
Public Sub AddFileToCollection(FileName As String, TheCollection As Collection)
Dim I As Long
Dim X As clsFileData
    'Set internal Properties
    Debug.Assert (m_FileName = "")
    m_FileName = FileName
    m_FileSize = FileLen(m_FileName)    'FileLen is SLOWWW, you'll want to use something else
    'Add to Collection
    If TheCollection.Count = 0 Then
        Call TheCollection.Add(Me)
        Exit Sub
    End If
    For I = 0 To TheCollection.Count - 1
        Set X = TheCollection.Item(I)
        If X.GetFileSize > m_FileSize Then
            Call TheCollection.Add(Me, Before:=I)
            Exit Sub
        End If
    Next I
    Call TheCollection.Add(Me, After:=TheCollection.Count - 1)
End Sub
Public Function GetFileName() As String
    GetFileName = m_FileName
End Function
Public Function GetFileSize() As Double
    GetFileSize = m_FileSize
End Function
'Function to copy the files to multiple CDs
Public Sub Main()
Dim Files As New Collection
Dim FileName As String
Dim X As clsFileData
    'Build a Collection of all Filenames in
    FileName = Dir("C:\CDDataFolder\*.*")
    Do While Len(FileName)
        Set X = New clsFileData
        Call X.AddFileToCollection(FileName, Files)
        FileName = Dir
    'Copy the Files to CD Folders
    Dim CDNum As Integer
    Dim RemainingSpace As Double
    Dim CDName As String
    CDNum = 0
    Dim FileName As String
    Do While Files.Count
        'Start the Next CD
        CDNum = CDNum + 1
        CDName = "C:\CDImage" & CStr(CDNum)
        MkDir CDName
        RemainingSpace = 700000000# - 20000000  '700MB - 20MB overhead
       'Find the next largest file that fits
        Do While Files.Count
            Dim I As Long
            FoundAFit As Boolean
            FoundAFit = False   'Flag that a file that fits hasn't been found
            For I = 0 To Files.Count - 1
                Set X = Files.Item(I)
                If X.GetFileSize <= RemainingSpace Then
                    'Update Remaining, Copy File, and remove from Collection
                    RemainingSpace = RemainingSpace - X.GetFileSize
                    FileCopy "C:\CDDataFolder\" & X.GetFileName, CDName & "\" & X.GetFileName
                    Call Files.Remove(I)
                    FoundAFit = True
                    Exit For
                End If
            Next I
            'Break Out of CD if nothing found that fit
            If FoundAFit = False Then
                Exit Do
            End If
End Sub

Open in new window

Assuming all files are <700MB individually, you can write an algorithm that starts by sorting all the files by size, then writing the largest file to disk 1, then calculate how much disk space would be left and write the largest file that would fit, and repeat until the disk is full, then start again for disk 2 etc
The last time I was dealing with collecting files into a directory to burn it to a CD, I had two issues to contend with.
1. The first issue is that CDs have storage units of 2K (2048) bytes in size, and a storage unit can be assigned to one and only one file.  That means if you have a file that is 2049 bytes in size, it's going to "eat" 4096 bytes on the CD because it will require two storage units to hold the file.

The easiest way to calculate how much of your 700MB of available storage is being wasted on partially used storage units is to assume that the average file "wastes" 1024 bytes.  If the size of your files are relatively random, this makes for a good estimate.  Other wise, as you process the size of each file, you must round the size of the file UP to the next 2K size.

Of course if you have less that 1,000 files to deal with, then the total "wasted" space is only going to be about 1MB.

2. The second issue is that when a CD indicates it can hold 700MB, that has to include the various FAT tables and directory structure.  But the "rules" for determining how much of your 700MB space is going to be needed by this "overhead" is EXTREAMLY complicated.  So the general rule of thumb used to be assume that 20MB of disk space will be used for this overhead.  However, if you have lots of small files, this rule of thumb can quickly be overwhelmed.  As a simple example, I used to build CD images with files that averaged about 10K.  That meant we were putting tens-of-thousands of files on CDs, and we generally had to allow for 50MB or more of "overhead" for that many files.
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

JohnnyAuthor Commented:
wow nice insite for both comments..

im more of looking of how to code this as a problem..but theory comments are welcome too..

any more code or insite on this problem would be most welcome..

thanks again as this still does not solve my problem.
So is the point that you are starting with a directory with >700MB (like WAY over 700MB) and you are trying to organize the files so that you can fit them on a minimum number of disks?

If so, then I would build a list of all the files that includes the file name, the files size, and a flag to indicate if the file has been copied to a logical CD yet.  Next, create your first logical CD and copy your largest file to that CD and mark the file as copied in the list.  Next, determine how much space is left on the 1st disk and find the next largest file in the list that has not been copied to a logical CD but fits within the remaining room on the first disk.  Repeat the process in a loop until there are no more files small enough to fit on the 1st disk.  Create a 2nd disk and copy the largest uncopied file to the CD.  Then repeat the process you did for disk 1.  Continue the process building how ever many disks are required.

The logic may not give you the absolute fewest number of disks, for to do that, it becomes a much more complex "shortest path" type logic problem.  But that's your trade-off complex logic to get the fewest number of CDs, or simple logic to get few ENOUGH CDs.  Given that blank CDs are really cheap, it's likely not worth the developement cost of pursuing the "shortest path" logic... and if I'm wrong about that, then perhaps you should be looking at putting data on DVDs rather than CDs.
disk Folder.  Start with your largest file and place
JohnnyAuthor Commented:
i actualy found a program that solved my imediate needs... atho i have always wanted to do this too. for backups etc. [ (may give you more info of what i was looking for)]
and would like to make this for our in house needs.

mathamaticaly i do not belive id be able to make a sorting code to break the logic down thw way you have suggested, would yo be so kind to provide code for this idea! please!

seams like a logical way of doing it and this would be needed for dvd's at one point too.. for now we are using cdr's as we do not have an in house dvd burner atho i do at my home (where I'm coding this for work)

ive attached the cd collection ive made so far, mind you i pieced together snips form another program i made, and ive just been playing with the ideas ive come across. it is by no means correct nor functional.
use the debug compiled program, [Draconic CD Collection\bin\Debug\Draconic CD Collection2.exe] and then in the tree use the CD/DVD Collection node (expand it) then click on Current CD/DVD Info it will then read the drive available then attempt to read the directories and gather the info. mind you no error checking nor major functionality yet. as i said it was a sandbox project and an area to play with ideas.
any farther ideas or code help would be most welcome to obtain the goal ive asked for here.

please find the sandbox project files at

again thank you for the nifty in sites. looking forward to the code reply.

JohnnyAuthor Commented:
i wont be able to check this till weekend thanks so much for reply
JohnnyAuthor Commented:
thank you so much
JohnnyAuthor Commented:
thank you works great as a stepping stone..was what i was looking for
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.