Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

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 vb.net 2008 pro for this project.
Avatar of ChloesDad
ChloesDad
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of HooKooDooKu
HooKooDooKu

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.
Avatar of Johnny

ASKER

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
Avatar of Johnny

ASKER

i actualy found a program that solved my imediate needs... atho i have always wanted to do this too. for backups etc. [ http://lars.werner.no/?page_id=2 (may give you more info of what i was looking for)]
and would like to make this for our in house needs.

HooKooDooKu:
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 http://dragon-software.info/ee/Draconic%20CD%20Collection.rar

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

ASKER CERTIFIED SOLUTION
Avatar of HooKooDooKu
HooKooDooKu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnny

ASKER

i wont be able to check this till weekend thanks so much for reply
Avatar of Johnny

ASKER

thank you so much
Avatar of Johnny

ASKER

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