0
first good morning!
I have a task to feed a "file tree (windows explorer style)" in object format.
For this I have initially a method that lists all the files and folders in the directory root
of the file system, and based on the typing of these (which may vary between Pasta
and Arquivo
) I must feed the property with the contents of that folder.
My problem is that I can only feed the first layer of this object, leaving its sub-folders still empty. That is, my call while
does not descend to the other levels.
Can anyone tell me what I did wrong?
public async Task<List<Arquivo>> ListarArquivosEPastas()
{
try
{
var arquivos = await ListarArquivosOuPastas("/");
foreach (var arquivo in arquivos)
{
while (arquivo.Tipo == "Pasta" && arquivo.Conteudo is null)
{
arquivo.Conteudo = await ListarArquivosOuPastasPorIdDiretorio(arquivo.Id);
}
}
return arquivos;
}
catch (Exception ex)
{
throw ex;
}
}
without seeing the code of the other methods and tbm knowing what to return in the variable files becomes quite difficult to help
– Ricardo Pontual
@Ricardopunctual They basically return a new array with the files and folders from that directory. I edited the post with an attached image of how this return is in detail
– Hudson Medeiros
look at this tree structure the secret will be in the method
ListarArquivosOuPastasPorIdDiretorio
, that there must be a recursive call, and also the class that will have this data will need if a kind of linked list, otherwise it will not get out of the first level. It needs to be something likeClass Arvore { Pasta Pasta {get; set; }
andClass Pasta { Pasta PastaPai { get; set; } List<Arquivo> Arquivos { get; set; } }
– Ricardo Pontual
If you have questions, let us know, then put an answer
– Ricardo Pontual