Forum: Ruby Copy data from many CDs using ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bobby S. (Guest)
on 2009-05-28 00:35
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!
Reid T. (Guest)
on 2009-05-28 00:44
(Received via mailing list)
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
Tom C. (Guest)
on 2009-05-28 02:58
(Received via mailing list)
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.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mk 2. (Guest)
on 2009-05-28 03:02
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.
Tom C. (Guest)
on 2009-05-28 03:15
(Received via mailing list)
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.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mk 2. (Guest)
on 2009-05-28 03:33
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.
Tom C. (Guest)
on 2009-05-28 04:04
(Received via mailing list)
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.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This topic is locked and can not be replied to.