Solved

List all files in a Folder of a Document Library

Posted on 2013-12-26
2
7,430 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Synchronize a new Active Directory domain with an existing Office 365 tenant
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

776 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