Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am able to search all folders with their name by using

$folder.Name.StartsWith("a")

this will display all folders which starts with name a in a Document Library.

I want all folders to be searched only from root level of Document library with name "a" and it should include all its subfolders inside it which can starts with any letter but property StartWith() doesn't exist for $RootFolder.SubFolders

any other way to do it?

share|improve this question

1 Answer 1

$RootFolder.SubFolders will give you the collection of folders. Loop through the collection and use StartsWith with each folder:

$folders =  $RootFolder.SubFolders;
foreach ($folder in $folders)
{
    if ($folder.Name.StartsWith("a"))
    {
         // Call $folder.Subfolders again to get folders present in this folder
         // Then use foreach to loop thru each folder and get files inside them
    }
}

UPDATE

Once inside the folder, call SubFolders again on the folder and then loop through all those folders to get files inside them.

share|improve this answer
    
what you have given is correct. but my requirement was to download all folders with name" a" at $RootFolder.SubFolders and also it should download all folders inside those folders which can starts with any name. –  SharePointer Mar 10 at 6:27
    
You did not mention about downloading in the question, even though I can see the download tag. But it will be better if you update the question –  Nadeem Yousuf Mar 10 at 6:31
    
yes.i will update the question. but any work around for it? –  SharePointer Mar 10 at 6:33
    
See my update answer –  Nadeem Yousuf Mar 10 at 6:47
    
Nadeem one more problem.i am ble to get folder level only till root subfolders..how to interate all folder levels –  SharePointer Mar 10 at 12:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.