Hello guys, i'm trying to list all folders from a directories, i done it, but not the way i want, when i say to list (Storage::directories('/mainfolder'), i get a list of sub-folders like...
mainfolder\. <----- this i dont want to list
mainfolder\.. <----- this i dont want to list
mainfolder\subfolder1 <--- this is ok
mainfolder\subfolder2 <--- this is ok
mainfolder\subfolder3 <--- this is ok
I would be recommending what @deadpix3l suggested. I'd advise against mucking around with parsing strings or assuming that the dot files will always be returned first. Use the functionality the language provides wherever possible, they've done the hard work so you don't have to.
I wouldn't like to assume that dot files are returned exactly the same in every call either. The DirectoryIterator class is part of the Standard PHP Library and is provided to allow all kinds of functionality that you could want from iterating through a directory structure. It's definitely the cleanest way to do what you were originally asking.
I think some people may misunderstand the purpose of the Storage service.
@mathiasgrimm perhaps the OP doesn't want to expose their filesystem or provide some way to allow end users to traverse up the file system from the base directory. Safety first ;)
@blackbird on a Linux-based system, the . (current) and .. (parent) directories are always present.
Given that the OP specifically asked about them, I made the reasonable assumption that he was a) working on a Linux-based system and b) would deploy to one.
@JoeDawson that solution would work, also; it's certainly simpler and much more reliable than assuming that the dotfiles will be returned first.