# Copy data from many CDs using ruby

**URL:** <https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971>\
**Category:** Ruby\
**Created:** [May 27, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971 "2009-05-27T22:35:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobbysantiago](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c89c15/32.png) [@bobbysantiago](https://www.ruby-forum.com/u/bobbysantiago)\
**Post date:** [May 27, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971/1 "2009-05-27T22:35:10Z")

</div>

Hi,

I am a beginner with very basic knowledge of ruby, but I would like to  
create a script that would do the following:

1. Prompt to input disc
2. Create a new sequential folder within a specified directory
3. Copy all files from disc into said folder
4. Eject disc
5. Prompt to input another disc

Essentially, I must copy the data off of ~1000 CDs and put the data into  
a separate folder for each disc. I would be doing this in a linux  
environment (ubuntu or debian).

Does anyone have any tips on where to start? Can this even be done with  
ruby? Thanks!

---

<div class="post-metadata">

**Author:** ![bobbysantiago](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c89c15/32.png) [@bobbysantiago](https://www.ruby-forum.com/u/bobbysantiago)\
**Post date:** [May 27, 2009, 10:44pm UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971/2 "2009-05-27T22:44:22Z")

</div>

On Thu, 2009-05-28 at 05:35 +0900, Bobby Sutter wrote:

> Essentially, I must copy the data off of ~1000 CDs and put the data into  
> a separate folder for each disc. I would be doing this in a linux  
> environment (ubuntu or debian).
> 
> Does anyone have any tips on where to start? Can this even be done with  
> ruby? Thanks!

google  
most likely yes, it can be done  
You might want to just write a bash script for it though

---

<div class="post-metadata">

**Author:** ![bobbysantiago](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c89c15/32.png) [@bobbysantiago](https://www.ruby-forum.com/u/bobbysantiago)\
**Post date:** [May 28, 2009, 12:58am UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971/3 "2009-05-28T00:58:28Z")

</div>

Bobby Sutter wrote:

> Essentially, I must copy the data off of ~1000 CDs and put the data into  
> a separate folder for each disc. I would be doing this in a linux  
> environment (ubuntu or debian).
> 
> Does anyone have any tips on where to start? Can this even be done with  
> ruby? Thanks!

Beginner? Me too, but I may know a bit more than you at this point. I  
know that the first time I tried to do something like this I ran into a  
few surprises. So…I’ll do for you what others here have done for me -  
an act of generosity that is rather often characteristic of this list -  
throw some code at you.

While the following code is rudimentary, it does meet your  
specifications - at least on my Kubuntu Linux OS. You may have to look  
up some things to make complete sense of it - or ask more questions.  
Hope this is useful.

# cds\_copy.rb

def main  
cd\_source = “/media/cdrom” # CDs read from here  
dirbase = “/home/tomc/Ruby-work/a-test” # new dirs created here  
dirstart = 0 # dir counter (for name creation)  
while true # loop forever until told to stop  
# Prompt to input disc  
puts “Load CD. Press enter when loaded. Enter ‘x’ to exit.”  
gets # input defaults to ‘$_’  
exit if /^x/ =~ $_  
system( “mount '” + cd\_source + "’" )  
# Create a new sequential folder within a specified directory  
foldernew = ( ‘CD’ + (dirstart.to\_i + 1).to\_s )  
dirstart += 1  
# Copy all files from disc into new folder  
FileUtils.cp\_r(cd\_source, foldernew) # recursive copy  
# Eject disc  
system( “eject '” + cd\_source + “’” )  
end  
end

require “fileutils”

main

# end file

Tom C.

–

```auto
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

```

---

<div class="post-metadata">

**Author:** ![bobbysantiago](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c89c15/32.png) [@bobbysantiago](https://www.ruby-forum.com/u/bobbysantiago)\
**Post date:** [May 28, 2009, 1:02am UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971/4 "2009-05-28T01:02:20Z")

</div>

Tom C. wrote:

> ```
> system( "mount '" + cd_source + "'" )
> 
> ```

There is a problem here in that most contemporary linux users use  
distros with auto-mounting. So either change the prompt to “Insert disk  
and hit enter AFTER cd is mounted” or use a sleep() of some appropriate  
duration.

---

<div class="post-metadata">

**Author:** ![bobbysantiago](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c89c15/32.png) [@bobbysantiago](https://www.ruby-forum.com/u/bobbysantiago)\
**Post date:** [May 28, 2009, 1:33am UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971/5 "2009-05-28T01:33:28Z")

</div>

Tom C. wrote:

> You see how helpful this list is? Thanks MK.

No problem. This one came up about a week ago and I thought it was  
funny because the first “learning” project I did (like, just) in ruby  
was to create a database of my DVD backups. Evidently newbie minds  
think alike, to some frightening degree.

I actually don’t use automounting, 'cause I find it irritating.

---

<div class="post-metadata">

**Author:** ![bobbysantiago](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c89c15/32.png) [@bobbysantiago](https://www.ruby-forum.com/u/bobbysantiago)\
**Post date:** [May 28, 2009, 1:15am UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971/6 "2009-05-28T01:15:26Z")

</div>

Mk 27 wrote:

> 

Erp. Well…

You are entirely correct. In my transition from Windows to Linux about a  
year ago, I found this whole CD mounting business a bit confusing. Then  
I figured out how to get it work and either learned an old-fashioned  
way, or the the OS moved to auto-mounting and I just didn’t notice (the  
latter, I think).

The code runs on my OS as written, but it also runs if one comments out  
this line

system( “mount '” + cd\_source + “’” )

and manually closes the CD and waits for the light to out.

Cool…My system (the one I run in my head) just got updated today.

You see how helpful this list is? Thanks MK.

t.

–

```auto
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

```

---

<div class="post-metadata">

**Author:** ![bobbysantiago](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c89c15/32.png) [@bobbysantiago](https://www.ruby-forum.com/u/bobbysantiago)\
**Post date:** [May 28, 2009, 2:04am UTC](https://www.ruby-forum.com/t/copy-data-from-many-cds-using-ruby/168971/7 "2009-05-28T02:04:34Z")

</div>

Mk 27 wrote:

> I actually don’t use automounting, 'cause I find it irritating.

That’s interesting. I do as well. Had it turned off on my WinX OS, and  
then just sorta forgot about it. For me it (obviously) ceased to exist.

t.

–

```auto
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

```
