Solved

List all files in a Folder of a Document Library

Posted on 2013-12-26
2
7,716 Views
Last Modified: 2013-12-29
Hi,

I want to user Powershell to list all the files in a particular folder in a document library. I tried the below and it does not work. Can help?

cls
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$webUrl = "http://sharepoint.com.sg/sites/SiteA"
$listName = "Trademark Opposition"

$sc = New-Object Microsoft.SharePoint.SPSite($webURL)
$web = $sc.OpenWeb()
$list = $web.Lists[$listName]

#Below code don't work... need advice what is the correct way
$foldFirstLvl = $list.Folders["Happy-Tiger Vitamin Functional Drink 11289668 in class 32"]
foreach ($item in $foldFirstLvl) {
   Write-Host $item.Name;
}

Open in new window

0
Comment
Question by:NicksonKoh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39741425
Hi,
the problem is that afaik there is no direct way to get a specific folder from the folder collection.
But on the web object there is the getfolder method - but you have to pass the complete URL path to it.
The following works on my dev environment (SP 2010 Enterprise):
cls
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$webUrl = "http://sharepoint.com.sg/sites/SiteA"
$listName = "Trademark Opposition"
$folderName = "Happy-Tiger Vitamin Functional Drink 11289668 in class 32"

$sc = New-Object Microsoft.SharePoint.SPSite($webURL)
$web = $sc.OpenWeb()
$list = $web.Lists[$listName]

#Get the folder reference based on the url AND use the Files property
$foldFirstLvl = $list.ParentWeb.GetFolder($web.Url + "/" + $list.RootFolder.Url + "/" + $folderName)
foreach ($item in $foldFirstLvl.Files) {
   Write-Host $item.Name
}

Open in new window


HTH
Rainer
0
 
LVL 17

Author Comment

by:NicksonKoh
ID: 39745447
Thx Rainer! Code works well and I am able to pick it from here. : )
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question