Example of building a list of file names?

  • Follow


Can anyone point me to an example of Java code that searches for all the 
files within a given Windows directory (and doesn't recurse into 
subdirectories) and then stores the file names in some kind of array or 
collection? For example, if my directory was c:\foo, it would store a list 
of all the files found in the foo directory.

I've lost most of my old code examples due to a hard drive crash and feel 
sure that this kind of code must have been done umpteen times before. I'll 
write it from scratch if I have to but I'm hoping some kind soul can point 
me to an example or just post it directly....

--
Rhino 


0
Reply Rhino 2/4/2010 7:13:59 PM

On 2/4/2010 2:13 PM, Rhino wrote:
> Can anyone point me to an example of Java code that searches for all the
> files within a given Windows directory (and doesn't recurse into
> subdirectories) and then stores the file names in some kind of array or
> collection? For example, if my directory was c:\foo, it would store a list
> of all the files found in the foo directory.
>
> I've lost most of my old code examples due to a hard drive crash and feel
> sure that this kind of code must have been done umpteen times before. I'll
> write it from scratch if I have to but I'm hoping some kind soul can point
> me to an example or just post it directly....

	String[] names = new File("c:\\foo").list();

I hope your new drive has enough room for this.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid
0
Reply Eric 2/4/2010 7:29:06 PM


On Thu, 4 Feb 2010 14:13:59 -0500, "Rhino"
<no.offline.contact.please@example.com> wrote, quoted or indirectly
quoted someone who said :

>Can anyone point me to an example of Java code that searches for all the 
>files within a given Windows directory (and doesn't recurse into 
>subdirectories) and then stores the file names in some kind of array or 
>collection? For example, if my directory was c:\foo, it would store a list 
>of all the files found in the foo directory.

see http://mindprod.com/products1.html#COMMANDLINE
-- 
Roedy Green Canadian Mind Products
http://mindprod.com

You can�t have great software without a great team, and most software teams behave like dysfunctional families. 
~ Jim McCarthy
0
Reply Roedy 2/4/2010 8:23:25 PM

"Eric Sosman" <esosman@ieee-dot-org.invalid> wrote in message 
news:hkf774$jeg$1@news.eternal-september.org...
> On 2/4/2010 2:13 PM, Rhino wrote:
>> Can anyone point me to an example of Java code that searches for all the
>> files within a given Windows directory (and doesn't recurse into
>> subdirectories) and then stores the file names in some kind of array or
>> collection? For example, if my directory was c:\foo, it would store a 
>> list
>> of all the files found in the foo directory.
>>
>> I've lost most of my old code examples due to a hard drive crash and feel
>> sure that this kind of code must have been done umpteen times before. 
>> I'll
>> write it from scratch if I have to but I'm hoping some kind soul can 
>> point
>> me to an example or just post it directly....
>
> String[] names = new File("c:\\foo").list();
>
> I hope your new drive has enough room for this.
>
> -- 
> Eric Sosman
> esosman@ieee-dot-org.invalid

I'm _REALLY_ rusty on my Java - haven't touched it in almost 4 years and I 
feel like I've forgotten almost everything. For some reason, I thought that 
was going to be more involved that it was.

Thanks, Eric!

--
Rhino 


0
Reply Rhino 2/4/2010 8:44:22 PM

"Roedy Green" <see_website@mindprod.com.invalid> wrote in message 
news:luamm5pkpbos5kdrjaruvp7j2k3fns5220@4ax.com...
> On Thu, 4 Feb 2010 14:13:59 -0500, "Rhino"
> <no.offline.contact.please@example.com> wrote, quoted or indirectly
> quoted someone who said :
>
>>Can anyone point me to an example of Java code that searches for all the
>>files within a given Windows directory (and doesn't recurse into
>>subdirectories) and then stores the file names in some kind of array or
>>collection? For example, if my directory was c:\foo, it would store a list
>>of all the files found in the foo directory.
>
> see http://mindprod.com/products1.html#COMMANDLINE
> -- 
> Roedy Green Canadian Mind Products
> http://mindprod.com
>
> You can't have great software without a great team, and most software 
> teams behave like dysfunctional families.
> ~ Jim McCarthy

Thank you! 


0
Reply Rhino 2/4/2010 8:44:37 PM

On 2/4/2010 3:44 PM, Rhino wrote:
> "Eric Sosman"<esosman@ieee-dot-org.invalid>  wrote in message
> news:hkf774$jeg$1@news.eternal-september.org...
>> On 2/4/2010 2:13 PM, Rhino wrote:
>>> Can anyone point me to an example of Java code that searches for all the
>>> files within a given Windows directory (and doesn't recurse into
>>> subdirectories) and then stores the file names in some kind of array or
>>> collection? For example, if my directory was c:\foo, it would store a
>>> list
>>> of all the files found in the foo directory.
>>>
>>> I've lost most of my old code examples due to a hard drive crash and feel
>>> sure that this kind of code must have been done umpteen times before.
>>> I'll
>>> write it from scratch if I have to but I'm hoping some kind soul can
>>> point
>>> me to an example or just post it directly....
>>
>> String[] names = new File("c:\\foo").list();
>>
>> I hope your new drive has enough room for this.
>>
>> --
>> Eric Sosman
>> esosman@ieee-dot-org.invalid
>
> I'm _REALLY_ rusty on my Java - haven't touched it in almost 4 years and I
> feel like I've forgotten almost everything. For some reason, I thought that
> was going to be more involved that it was.

     One thing you appear to have forgotten in the existence
of something called "Javadoc" ...

     (Another is that quoting Usenet signatures is frowned
upon.  Have a care, or Lew will chastise you!)

-- 
Eric Sosman
esosman@ieee-dot-org.invalid
0
Reply Eric 2/4/2010 9:38:04 PM

On Thu, 04 Feb 2010 14:29:06 -0500, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote, quoted or indirectly quoted
someone who said :

>
>	String[] names = new File("c:\\foo").list();

that  is a fairly small list.  list does not recurse for you.
-- 
Roedy Green Canadian Mind Products
http://mindprod.com

You can�t have great software without a great team, and most software teams behave like dysfunctional families. 
~ Jim McCarthy
0
Reply see_website (4858) 2/5/2010 4:30:52 PM

On 2/5/2010 11:30 AM, Roedy Green wrote:
> On Thu, 04 Feb 2010 14:29:06 -0500, Eric Sosman
> <esosman@ieee-dot-org.invalid>  wrote, quoted or indirectly quoted
> someone who said :
>
>> 	String[] names = new File("c:\\foo").list();
>
> that  is a fairly small list.  list does not recurse for you.

     The O.P. asked for "an example of Java code that searches
for all the  files within a given Windows directory (and doesn't
recurse into subdirectories)."

     Harrumph.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid
0
Reply esosman2 (2945) 2/5/2010 4:50:22 PM

On 05-02-2010 11:50, Eric Sosman wrote:
> On 2/5/2010 11:30 AM, Roedy Green wrote:
>> On Thu, 04 Feb 2010 14:29:06 -0500, Eric Sosman
>> <esosman@ieee-dot-org.invalid> wrote, quoted or indirectly quoted
>> someone who said :
>>
>>> String[] names = new File("c:\\foo").list();
>>
>> that is a fairly small list. list does not recurse for you.
>
> The O.P. asked for "an example of Java code that searches
> for all the files within a given Windows directory (and doesn't
> recurse into subdirectories)."
>
> Harrumph.

Reading what he comment on does not seem to be Roedy's
strong side.

Arne

0
Reply arne6 (9485) 2/6/2010 12:59:35 AM

On Fri, 05 Feb 2010 11:50:22 -0500, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote, quoted or indirectly quoted
someone who said :

>     The O.P. asked for "an example of Java code that searches
>for all the  files within a given Windows directory (and doesn't
>recurse into subdirectories)."
>
>     Harrumph.

Sorry about that.  I saw the word "recurse" and thought -- he needs
help with recursion. I could see someone asking for help with
recursion but not with File.list which is completely straightforward.

Most newbie questions to me read like gibberish, so I tend just to
skim them, even when they are coherent.  I pick out a few keywords and
guess what the user is actually asking. Most of you are much better at
interpreting them literally.

I am more interested in the general audience than the particular
newbie, so it is not of paramount importance that I answer their
question specifically, just that I put out something useful on the
general topic. I figure a newbie asking a particular question is
probably lacking in background.  With background, they can often
answer their own question.  I generally frown on spoon feeding.  I
like to make the newbie stretch a bit.


-- 
Roedy Green Canadian Mind Products
http://mindprod.com

Every compilable program in a sense works. The problem is with your unrealistic expections on what it will do.
0
Reply see_website (4858) 2/7/2010 6:54:18 AM

On 07-02-2010 01:54, Roedy Green wrote:
> On Fri, 05 Feb 2010 11:50:22 -0500, Eric Sosman
> <esosman@ieee-dot-org.invalid>  wrote, quoted or indirectly quoted
> someone who said :
>>      The O.P. asked for "an example of Java code that searches
>> for all the  files within a given Windows directory (and doesn't
>> recurse into subdirectories)."
>
> Sorry about that.  I saw the word "recurse" and thought -- he needs
> help with recursion. I could see someone asking for help with
> recursion but not with File.list which is completely straightforward.
>
> Most newbie questions to me read like gibberish, so I tend just to
> skim them, even when they are coherent.  I pick out a few keywords and
> guess what the user is actually asking.

That is not particular respectful for the people writing and reading
here.

>                                        Most of you are much better at
> interpreting them literally.
>
> I am more interested in the general audience than the particular
> newbie, so it is not of paramount importance that I answer their
> question specifically, just that I put out something useful on the
> general topic. I figure a newbie asking a particular question is
> probably lacking in background.  With background, they can often
> answer their own question.  I generally frown on spoon feeding.  I
> like to make the newbie stretch a bit.

Well - in this case you did not reply to a newbie but to Eric.

Arne
0
Reply arne6 (9485) 2/8/2010 1:07:36 AM

10 Replies
178 Views

(page loaded in 0.114 seconds)

Similiar Articles:













7/25/2012 12:31:12 PM


Reply: