J
Jabari Zakiya
I'm trying to figure out the best way to accomplish this task.
Being new to Ruby, I'm trying to be efficient (if not elegant),
but first just want something that works.
I'm using Ruby 1.8.2 rc4 on Windows 2000.
Here's the task.
--------------
I have text files of lastnames, one name per line.
I want to read each name from each file, and determine
if that name is part of any file which has the extensions
*.txt or *.doc or *.rtf which occur in any directory within
the tree structure for a given top level directory.
The human interface is something simple like this:
The text filename is keyboard entered into "NameListFile".
The top-level-dir is keyboard entered into "DirToSearch".
The output-file is keyboard entered into "SearchResults".
Doing something like: DirItems = Dir.entries(DirToSearch)
I can get an array of items in the top-level directory.
Given this array of files and directories, I just need to
check to see if an item is a "file" or "directory".
If its a "file" I check to see that its extension is
*.txt or *.doc or *.rtf. If the file has any of those
extensions, I then check to see whether the filename
contains, in any part, a name from "NameListFile".
If YES, I print the name in an output file in the formant:
Name, filedate, filename(fullpath relative to "DirToSearch")
If an item in DirItems is a "directory" then I do the checking
process for the entries in that directory, etc, etc, untill
every file in every directory is searched.
It seems this is a natural case to use recursion to check all
the directories in the tree, but I'm not sure which methods
to use to do this.
This seems like a pretty easy/standard thing to do, but I just
don't know enough ruby (yet) to do it easy.
Your help and guidance is appreciated in advance.
Jabari
Being new to Ruby, I'm trying to be efficient (if not elegant),
but first just want something that works.
I'm using Ruby 1.8.2 rc4 on Windows 2000.
Here's the task.
--------------
I have text files of lastnames, one name per line.
I want to read each name from each file, and determine
if that name is part of any file which has the extensions
*.txt or *.doc or *.rtf which occur in any directory within
the tree structure for a given top level directory.
The human interface is something simple like this:
The text filename is keyboard entered into "NameListFile".
The top-level-dir is keyboard entered into "DirToSearch".
The output-file is keyboard entered into "SearchResults".
Doing something like: DirItems = Dir.entries(DirToSearch)
I can get an array of items in the top-level directory.
Given this array of files and directories, I just need to
check to see if an item is a "file" or "directory".
If its a "file" I check to see that its extension is
*.txt or *.doc or *.rtf. If the file has any of those
extensions, I then check to see whether the filename
contains, in any part, a name from "NameListFile".
If YES, I print the name in an output file in the formant:
Name, filedate, filename(fullpath relative to "DirToSearch")
If an item in DirItems is a "directory" then I do the checking
process for the entries in that directory, etc, etc, untill
every file in every directory is searched.
It seems this is a natural case to use recursion to check all
the directories in the tree, but I'm not sure which methods
to use to do this.
This seems like a pretty easy/standard thing to do, but I just
don't know enough ruby (yet) to do it easy.
Your help and guidance is appreciated in advance.
Jabari