[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Copy data from many CDs using ruby

Bobby Sutter

5/27/2009 8:35:00 PM

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!
--
Posted via http://www.ruby-....

6 Answers

Reid Thompson

5/27/2009 8:43:00 PM

0

On Thu, 2009-05-28 at 05:35 +0900, Bobby Sutter wrote:
> 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!

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

Tom Cloyd

5/27/2009 10:57:00 PM

0

Bobby Sutter wrote:
> 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!
>
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 Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


MK

5/27/2009 11:02:00 PM

0

Tom Cloyd 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.
--
Posted via http://www.ruby-....

Tom Cloyd

5/27/2009 11:14:00 PM

0

Mk 27 wrote:
> Tom Cloyd 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.
>
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 Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


MK

5/27/2009 11:34:00 PM

0

Tom Cloyd 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.
--
Posted via http://www.ruby-....

Tom Cloyd

5/28/2009 12:03:00 AM

0

Mk 27 wrote:
> Tom Cloyd 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.
>
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 Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~