# Newbie-Script for copying matching files to new destination

**URL:** <https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899>\
**Category:** Ruby\
**Created:** [May 13, 2009, 7:20pm UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899 "2009-05-13T19:20:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sansouchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sansouchi](https://www.ruby-forum.com/u/sansouchi)\
**Post date:** [May 13, 2009, 7:20pm UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899/1 "2009-05-13T19:20:58Z")

</div>

Hi,  
Being new to Ruby,am not sure if it can do these but if it can then  
someone please help.My challenge is that I want to copy certain files  
from a source location with filenames containing words listed in a text  
file to a new location. Any help would be most appreciated.Thanks in  
advance.

---

<div class="post-metadata">

**Author:** ![sansouchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sansouchi](https://www.ruby-forum.com/u/sansouchi)\
**Post date:** [May 13, 2009, 8:36pm UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899/2 "2009-05-13T20:36:09Z")

</div>

On 13.05.2009 19:21, Os Ai wrote:

> Being new to Ruby,am not sure if it can do these but if it can then  
> someone please help.My challenge is that I want to copy certain files  
> from a source location with filenames containing words listed in a text  
> file to a new location. Any help would be most appreciated.Thanks in  
> advance.

I am not sure what you are asking for… How about:

1. read words from file
2. enumerate all files in the source location and check each name for a  
match
3. if there is a match copy the file from source to target

Cheers

robert

---

<div class="post-metadata">

**Author:** ![sansouchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sansouchi](https://www.ruby-forum.com/u/sansouchi)\
**Post date:** [May 13, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899/3 "2009-05-13T20:43:24Z")

</div>

Robert K. wrote:

> On 13.05.2009 19:21, Os Ai wrote:
> 
> > Being new to Ruby,am not sure if it can do these but if it can then  
> > someone please help.My challenge is that I want to copy certain files  
> > from a source location with filenames containing words listed in a text  
> > file to a new location. Any help would be most appreciated.Thanks in  
> > advance.
> 
> I am not sure what you are asking for… How about:
> 
> 1. read words from file
> 2. enumerate all files in the source location and check each name for a  
> match
> 3. if there is a match copy the file from source to target
> 
> Cheers
> 
> robert

Hi Robert,  
Yes you got it. I guess you know how to speak ‘programming’ which I  
obviously don’t.So how do I go about it?

---

<div class="post-metadata">

**Author:** ![sansouchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sansouchi](https://www.ruby-forum.com/u/sansouchi)\
**Post date:** [May 13, 2009, 9:15pm UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899/4 "2009-05-13T21:15:48Z")

</div>

On 13.05.2009 20:43, Os Ai wrote:

> > 1. enumerate all files in the source location and check each name for a  
> > match
> > 2. if there is a match copy the file from source to target

> Yes you got it. I guess you know how to speak ‘programming’ which I  
> obviously don’t.So how do I go about it?

Assuming you are completely new to programming you probably want to  
start here [http://pine.fm/LearnToProgram/](http://pine.fm/LearnToProgram/) or with any other introductory  
tutorial for Ruby and then look up documentation about these core and  
standard library classes

String  
Array  
File  
Dir  
Find

You’ll find it here [RDoc Documentation](http://www.ruby-doc.org/core-1.9/index.html) and  
[RDoc Documentation](http://www.ruby-doc.org/stdlib/). You can also find some hints about  
file reading in our blog, although I suggest you first consider Chris’s  
book:

[http://blog.rubybestpractices.com/posts/rklemme/001-Using\_blocks\_for\_Robustness.html](http://blog.rubybestpractices.com/posts/rklemme/001-Using_blocks_for_Robustness.html)

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![sansouchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sansouchi](https://www.ruby-forum.com/u/sansouchi)\
**Post date:** [May 14, 2009, 12:24am UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899/5 "2009-05-14T00:24:45Z")

</div>

Hi Robert,  
Thanks for even taking time to write and even advice.Am indeed  
grateful.I would research on all the literature since am new to Ruby.I  
would still like to be guided on how to go about it as I need it  
urgently.Thanks

---

<div class="post-metadata">

**Author:** ![sansouchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sansouchi](https://www.ruby-forum.com/u/sansouchi)\
**Post date:** [May 15, 2009, 9:43am UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899/6 "2009-05-15T09:43:07Z")

</div>

Thanks for your post. You have raised very valid points. I am learning  
and hopefully would be able to find a solution in a few days. Thanks  
again.

---

<div class="post-metadata">

**Author:** ![sansouchi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85f322/32.png) [@sansouchi](https://www.ruby-forum.com/u/sansouchi)\
**Post date:** [May 14, 2009, 10:12am UTC](https://www.ruby-forum.com/t/newbie-script-for-copying-matching-files-to-new-destination/167899/7 "2009-05-14T10:12:50Z")

</div>

2009/5/14 Os Ai [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Thanks for even taking time to write and even advice.Am indeed  
> grateful.I would research on all the literature since am new to Ruby.I  
> would still like to be guided on how to go about it as I need it  
> urgently.Thanks

Learning and urgency do not mix well. If you are new to programming  
you cannot expect to learn it overnight.

This forum is generally very helpful, however to me it feels like this  
question has “do my (home) work for me” written all over it. You have  
not demonstrated that you followed advice given or what you attempted  
yourself yet expect “guidance” and try to push us. This usually does  
not work well with volunteers. For more elaborate explanations please  
read:

[http://catb.org/esr/faqs/smart-questions.html#urgent](http://catb.org/esr/faqs/smart-questions.html#urgent)

Regards

robert
