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

Posted on 2009-05-10
Last Modified: 2012-05-06
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.
Question by:Johnny
  • 5
  • 3
LVL 15

Expert Comment

ID: 24348926
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
LVL 16

Expert Comment

ID: 24354141
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.

Author Comment

ID: 24360772
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.
LVL 16

Expert Comment

ID: 24365415
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.


Author Comment

ID: 24379285
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.

LVL 16

Accepted Solution

HooKooDooKu earned 500 total points
ID: 24379934
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


Author Comment

ID: 24380744
i wont be able to check this till weekend thanks so much for reply

Author Closing Comment

ID: 31579913
thank you so much

Author Comment

ID: 24420757
thank you works great as a stepping stone..was what i was looking for

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.net VBA word safemode 1 37
Change data in datatable 8 30
Help with WinAPI Signatures in VB.NET for SetWindowSubclass 2 34
VB.Net How to Exit Sub - Exit Form??? 5 50
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now