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: Reading a directory and selecting only desired filenames - comp ...The following code reads a directory and places all the filenames into a SAS dataset. I would like only file names starting with "ABC" for example. P... passing a list of files to awk - comp.lang.awkSomehow, when I try to pass a list of files to awk, I only get awk listing file names and waiting... ... Consider the following example: $ echo "Hello $LOGNAME, it's ... Read wav file from a path name - comp.soft-sys.matlabHello, I'm building a GUI for a listening ... Basically you need to read your folder name from your text file ... > Here's a GUi example that allows the user to ... Help needed: read 3-dimensional array from a MAT-file in Fortran ...... matfile.f file for an example of loading variables from a mat file, and ... some reason why you are building a ... List of variable names in the file:" > names ... tar exclude file issue - comp.unix.solarisUse the exclude-file argument as a FILE containing a list of relative path names ... > When I issue the following command for example: > tar ... List image file names in a field and creating photo viewer - comp ...Imagine a real estate database (not my scenario, but an easier example than ... List image file names in a field and creating photo viewer - comp ... Insert graphic from ... read and merge lots of txt files, macro? - comp.soft-sys.sas ...Type one file contains a list of varible names (character var). Type two file contains ... with columns of data and the first row is the var names. For example, the file ... Filtered drop down value list not filtering - comp.databases ...The idea is to display the vendor's name ... second rel to vendors... have set an example file ... Building a Drop-Down Filter List for a DataGridView Column Header Cell ... Recursive ctags on Solaris - comp.unix.programmer... files with ctags ? > man ctags gives an example: Example 2: Building a tags file ... example% cd sourcedir ; rm -f tags ; touch tags example% find . \( -name ... Characters permitted in file names - comp.unix.programmer ...Is anyone able to let me have a list of the ASCII characters which are not permitted as a file name in a POSIX ... may be up to 255 characters in length ===== EXAMPLES OF Create a directory of names, addresses, and other information ...For example, the list of names and addresses you want to use in a mail merge. ... Save Address List dialog box, type a name for the address list in the File name box ... Spreadsheet Page Excel Tips: Getting A List Of File NamesGetting A List Of File Names. Category: General | Many users are surprised to discover ... redirect the output to a file, use the > character and specify a file name. For example ... 7/25/2012 12:31:12 PM
|