Solved

List all files in a Folder of a Document Library

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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
Synchronize a new Active Directory domain with an existing Office 365 tenant
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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