# Get new files in dstdir before cp\_r

**URL:** <https://www.ruby-forum.com/t/get-new-files-in-dstdir-before-cp-r/86985>\
**Category:** Ruby\
**Created:** [February 27, 2007, 11:37am UTC](https://www.ruby-forum.com/t/get-new-files-in-dstdir-before-cp-r/86985 "2007-02-27T11:37:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 27, 2007, 11:37am UTC](https://www.ruby-forum.com/t/get-new-files-in-dstdir-before-cp-r/86985/1 "2007-02-27T11:37:28Z")

</div>

Hi,

i have a workflow that copies folders with FileUtils.cp\_r  
over to an existing cvs workspace.

As cvs CLI lacks a recursive flag for add command,  
i have to add all new folders and files separately in  
a spaceseparated list, i.e.

cvs add ./subfolder1 ./subfolder1/subsub1  
./subfolder1/subsub1/subsub.txt  
so i have to calculate all new files.

i have tried to get the new files with =

def copy\_dir(dir)  
updfiles=Array.new  
Dir.glob("#{dir}/\*\*/_[^coinfo.txt]._").each do | i |  
if not File.exist?("#{CVSWORKSPACE}/#{i}")  
puts “new file detected ==\> #{i}”  
end  
end  
end

but i get =

new file detected ==\> Y:/test\_deploy/4804/subfolder7/subsub7/bla.txt  
new file detected ==\>  
Y:/test\_deploy/4804/subfolder7/subsub7/subsubsub7/subsubsub7.txt  
new file detected ==\> Y:/test\_deploy/4804/subfolder7/subsub6/subsub6.txt  
new file detected ==\>  
Y:/test\_deploy/4804/subfolder7/subsub6/subsubsub6/subsubsub6.txt

means the whole path, where i would need the space separated list like  
that =

/subfolder7 /subfolder7/subsub7 /subfolder7/subsub7/bla.txt …

How to achieve that ?

As i use the FileUtils.cp\_r method later =  
doesn’t this method not already know internally which files are new ?

Regards, Gilbert

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 27, 2007, 11:46am UTC](https://www.ruby-forum.com/t/get-new-files-in-dstdir-before-cp-r/86985/2 "2007-02-27T11:46:29Z")

</div>

On Tue, Feb 27, 2007 at 07:36:26PM +0900, Rebhan, Gilbert wrote:

> that =
> 
> /subfolder7 /subfolder7/subsub7 /subfolder7/subsub7/bla.txt …
> 
> How to achieve that ?

Try:

Dir.chdir(dir) do  
Dir.glob("\*\*/_[^coinfo.txt]._").each do |i|  
puts i  
end  
end
