• Post Reply Bookmark Topic Watch Topic
  • New Topic

Return content of directory  RSS feed

 
Mads Nielsen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have this function (snippet) i would like to make the function return the content of the directory (documentation)

This static way of doing it works fine.


This also works fine:


But what i really want is to make it dynamic. like this:


The last way does obviously not work. (hence this post)

How do i solve this ?

Kind regards Mads Nielsen
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the question, or the purpose of the code, or something like that. To return the contents of the directory I would do this:


You have some more complicated code which you say "works", although I don't understand what you mean by that because your code doesn't return the contents of the directory. So perhaps you could explain what your actual goal is.
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he needs a string whit a list of files/directories in the given directory separated by a comma.
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mads,
you can create a String with commas and can then return.
 
Mads Nielsen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry.

this is the full function:



I want to make the return statement dynamic.

I think bhanu chowdary's solution is pretty close. But i have no idea how to implement it in the current function.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mads Nielsen wrote:I think bhanu chowdary's solution is pretty close. But i have no idea how to implement it in the current function.


Bhanu thinks you need a String. Your code attempt returns an array of Strings. But you think Bhanu is right? Then I think you need to produce a clear statement of what you want first.
 
Mads Nielsen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i think Bhanu is pretty close.

What i need is this:



But since i dont know how many files and directories there is going to be in the directory i want it to be dynamic. I tried to use a for loop (first post) but that dident work.



 
Mads Nielsen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out now.

Thanks Paul



It was that simple.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except now you're calling dir.list() twice, causing the directory contents to be retrieved twice.

Paul already provided your code minus the second call in the very first reply in this thread. What was wrong with that?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!