On Wed, Sep 14, 2011 at 6:44 PM, Jarvis, Matthew <[email protected]> wrote:
>
> These _vti_cnf folders are all marked with the Hidden attribute.
>
> So anyway, when I produce the listing I do something like this:
>
> dir /b /s /A-H | findstr ".doc" | sort > myfile.txt
>
> So I guess the command line kung-fu I am wanting is a way to get a list
> of all the *.doc files, in all the subdirs that are not marked as
> Hidden. (I'll sort it myself later).
>
> Any takers?
>

Sure. First, I think the problem is that the hidden attribute test is
failing because it's only on the directory and not on the files. I
think you really just want to skip any file that has '_vti_cnf' in its
directory path. Here's a snippet in Ruby that will do that:

I'll set up a test tree on Linux:

[troche@saturn ~]$ mkdir test
[troche@saturn ~]$ mkdir test/dir_a
[troche@saturn ~]$ mkdir test/_vti_cnf
[troche@saturn ~]$ mkdir test/dir_a/_vti_cnf
[troche@saturn ~]$ touch test/file1
[troche@saturn ~]$ touch test/dir_a/file2
[troche@saturn ~]$ touch test/dir_a/file3
[troche@saturn ~]$ touch test/dir_a/file4
[troche@saturn ~]$ touch test/_vti_cnf/file5
[troche@saturn ~]$ touch test/_vti_cnf/file6
[troche@saturn ~]$ touch test/_vti_cnf/file7
[troche@saturn ~]$ tree test
test
|-- dir_a
|   |-- file2
|   |-- file3
|   |-- file4
|   `-- _vti_cnf
|-- file1
`-- _vti_cnf
    |-- file5
    |-- file6
    `-- file7

I stole this code from stack overflow
(http://stackoverflow.com/questions/1281090/whats-the-ruby-equivalent-of-pythons-os-walk)
which was close enough to what you needed done and hacked out the
extras. I added the last line just to print out the results.

Save this to a file on any decent operating system that comes with
Ruby (or install Ruby on any deficient OS :)
(http://www.ruby-lang.org/en/downloads/) and this should do the trick:

#! /bin/env ruby
require 'pathname'

def os_walk(dir)
  root = Pathname(dir)
  files = []
  Pathname(root).find {|path| files << path if path.file? and path !=
root and !path.to_s.include? 'vti_cnf'}
  [root, files]
 end

root, files = os_walk('./test/')

files.reverse_each {|f| print f.to_s + "\n" }

*-- snip here --*
Run the file and you'll get:

[troche@saturn ~]$ ./oswalk.rb
./test/file1
./test/dir_a/file4
./test/dir_a/file3
./test/dir_a/file2

I just noticed I skipped the requirement for .doc files. Easy enough
to do, just add 'and path.to_s.downcase.include? '.doc' in the long
line of Pathname... above.

-- 
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/cacw6n4tyxp8gqpq0gvq_4dgz9wmxspgeqhj4p1xzxxm2ehn...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to