Solved

List all files in a Folder of a Document Library

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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