I'm working on a script that's currently using Find.find to process a
complete directory tree of files and directories .. .however I needed
specific behavior, and I'm still fairly new to this...
Basically it works like this, the user specifies the root directory of a
collection of sub-directories we are interested in .. for instance:
But we are only interested in the _files_ in \Dir1 , \Dir2 ..and want to
essentially Prune recursion into C:\Root\Dir1\Subdir_of_Dir1 , and
C:\Root\Dir2\Subdir_of_Dir2 if those exist ..
This is what I am currently using, however it will pick up the sub
directories of Dir1 and Dir2 and update the hash... Does anyone see any way
this could be refactored to not update the "process_list" hash with the sub
directories of Dir1 and Dir2?
···
--
@root_dir = "C:\Root"
process_list = Hash.new {|h,k| h[k] = []}
Find.find(@root_dir.to_s) do |f|
f = f.gsub(/\\/,'/')
next if File.stat(f).directory? or f.include?('skipped_filename')
Find.prune if f.include?("skipped_dirname")
d, b = File.split(f)
process_list [d] << b
end
I'm working on a script that's currently using Find.find to process a
complete directory tree of files and directories .. .however I needed
specific behavior, and I'm still fairly new to this...
Basically it works like this, the user specifies the root directory of a
collection of sub-directories we are interested in .. for instance:
But we are only interested in the _files_ in \Dir1 , \Dir2 ..and want to
essentially Prune recursion into C:\Root\Dir1\Subdir_of_Dir1 , and
C:\Root\Dir2\Subdir_of_Dir2 if those exist ..
This is what I am currently using, however it will pick up the sub
directories of Dir1 and Dir2 and update the hash... Does anyone see any way
this could be refactored to not update the "process_list" hash with the sub
directories of Dir1 and Dir2?
--
@root_dir = "C:\Root"
process_list = Hash.new {|h,k| h[k] = }
Find.find(@root_dir.to_s) do |f|
f = f.gsub(/\\/,'/')
next if File.stat(f).directory? or f.include?('skipped_filename')
Find.prune if f.include?("skipped_dirname")
d, b = File.split(f)
process_list [d] << b
end
Thanks in advance!
Brian
Perhaps you would like file-find better. I think this is what you want:
Dir["#{@root_dir}/*/*"].each do |f|
next unless File.file? f
d, b = File.split f
process_list[d] << b
end
Kind regards
robert
···
2009/9/15 Brian Wallace <draygen80@gmail.com>:
Hi all,
I'm working on a script that's currently using Find.find to process a
complete directory tree of files and directories .. .however I needed
specific behavior, and I'm still fairly new to this...
Basically it works like this, the user specifies the root directory of a
collection of sub-directories we are interested in .. for instance:
But we are only interested in the _files_ in \Dir1 , \Dir2 ..and want to
essentially Prune recursion into C:\Root\Dir1\Subdir_of_Dir1 , and
C:\Root\Dir2\Subdir_of_Dir2 if those exist ..
This is what I am currently using, however it will pick up the sub
directories of Dir1 and Dir2 and update the hash... Does anyone see any way
this could be refactored to not update the "process_list" hash with the sub
directories of Dir1 and Dir2?
--
@root_dir = "C:\Root"
process_list = Hash.new {|h,k| h[k] = }
Find.find(@root_dir.to_s) do |f|
f = f.gsub(/\\/,'/')
next if File.stat(f).directory? or f.include?('skipped_filename')
Find.prune if f.include?("skipped_dirname")
d, b = File.split(f)
process_list [d] << b
end
I'm working on a script that's currently using Find.find to process a
complete directory tree of files and directories .. .however I needed
specific behavior, and I'm still fairly new to this...
This is what I am currently using, however it will pick up the sub
directories of Dir1 and Dir2 and update the hash... Does anyone see any way
this could be refactored to not update the "process_list" hash with the sub
directories of Dir1 and Dir2?
--
@root_dir = "C:\Root"
process_list = Hash.new {|h,k| h[k] = }
Find.find(@root_dir.to_s) do |f|
f = f.gsub(/\\/,'/')
next if File.stat(f).directory? or f.include?('skipped_filename')
Find.prune if f.include?("skipped_dirname")
d, b = File.split(f)
process_list [d] << b
end
Of course I recommend my RbFind tool. It is pure Ruby, no C to
compile.
That would actually work out OK - however since i'm using JRuby I wouldn't
be able to use a gem with native C extensions..
Thanks for the suggestion!
Brian
···
On Tue, Sep 15, 2009 at 9:48 PM, Daniel Berger <djberg96@gmail.com> wrote:
Brian Wallace wrote:
Hi all,
I'm working on a script that's currently using Find.find to process a
complete directory tree of files and directories .. .however I needed
specific behavior, and I'm still fairly new to this...
Basically it works like this, the user specifies the root directory of a
collection of sub-directories we are interested in .. for instance:
But we are only interested in the _files_ in \Dir1 , \Dir2 ..and want to
essentially Prune recursion into C:\Root\Dir1\Subdir_of_Dir1 , and
C:\Root\Dir2\Subdir_of_Dir2 if those exist ..
This is what I am currently using, however it will pick up the sub
directories of Dir1 and Dir2 and update the hash... Does anyone see any
way
this could be refactored to not update the "process_list" hash with the
sub
directories of Dir1 and Dir2?
--
@root_dir = "C:\Root"
process_list = Hash.new {|h,k| h[k] = }
Find.find(@root_dir.to_s) do |f|
f = f.gsub(/\\/,'/')
next if File.stat(f).directory? or f.include?('skipped_filename')
Find.prune if f.include?("skipped_dirname")
d, b = File.split(f)
process_list [d] << b
end
Thanks in advance!
Brian
Perhaps you would like file-find better. I think this is what you want:
Hrrm - A simple solution of course ... and I've spent all this time trying
to figure it out on my own , without asking for help!
You've helped me in the past with a few other problems, and you were spot on
each time ..
I envy you, and hope that I am able to become even as half as knowledgeable
as you are..
Best Regards,
Brian
···
On Wed, Sep 16, 2009 at 2:51 AM, Robert Klemme <shortcutter@googlemail.com>wrote:
2009/9/15 Brian Wallace <draygen80@gmail.com>:
> Hi all,
>
> I'm working on a script that's currently using Find.find to process a
> complete directory tree of files and directories .. .however I needed
> specific behavior, and I'm still fairly new to this...
>
> Basically it works like this, the user specifies the root directory of a
> collection of sub-directories we are interested in .. for instance:
>
> User specifies: C:\Root
>
> C:\Root
> >
> -->\Dir1
> >
> -->Files_in_dir1
> >
> -->\Dir2
> >
> -->Files_in_dir2
>
>
> But we are only interested in the _files_ in \Dir1 , \Dir2 ..and want to
> essentially Prune recursion into C:\Root\Dir1\Subdir_of_Dir1 , and
> C:\Root\Dir2\Subdir_of_Dir2 if those exist ..
>
> This is what I am currently using, however it will pick up the sub
> directories of Dir1 and Dir2 and update the hash... Does anyone see any
way
> this could be refactored to not update the "process_list" hash with the
sub
> directories of Dir1 and Dir2?
>
> --
>
> @root_dir = "C:\Root"
>
> process_list = Hash.new {|h,k| h[k] = }
>
> Find.find(@root_dir.to_s) do |f|
> f = f.gsub(/\\/,'/')
> next if File.stat(f).directory? or f.include?('skipped_filename')
> Find.prune if f.include?("skipped_dirname")
> d, b = File.split(f)
> process_list [d] << b
> end
>
> Thanks in advance!
require 'no gems' # silly joke
Dir["#{@root_dir}/*/*"].each do |f|
next unless File.file? f
d, b = File.split f
process_list[d] << b
end
There's a JRuby specific gem for file-find. A simple "gem install file-
find" should work, but if it doesn't try "gem install file-find --
platform=java" and see if that works.
Regards,
Dan
···
On Sep 16, 7:43 am, Brian Wallace <drayge...@gmail.com> wrote:
Thanks Dan,
That would actually work out OK - however since i'm using JRuby I wouldn't
be able to use a gem with native C extensions..