[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

get new files in dstdir before cp_r

Rebhan, Gilbert

2/27/2007 10:36:00 AM


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



1 Answer

Brian Candler

2/27/2007 10:46:00 AM

0

On Tue, Feb 27, 2007 at 07:36:26PM +0900, Rebhan, Gilbert wrote:
> 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 ?

Try:

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