In a 2010 site colelction I have a document library with a complicated structure and lots of subfolders that I want to move to a flat structure. How can I get a hierarchical list of all (sub-)folders and all files? Maybe with powershell (v1)?

2 Answers 2


You can use PowerShell to get this information

Function GetFiles($folder)
    Write-Host $folder.Name
    foreach($file in $folder.Files)
       Write-Host $file.Name
    foreach ($subFolder in $folder.SubFolders)

$web = Get-SPWeb http://weburl
$list = $web.Lists["ListName"]
  • It works with SP2013 but not in 2010 (ps 1.0), it doesn't find my site collection. How do I get this to work with my old SharePoint?
    – jlai
    May 18, 2015 at 13:07
  • Have you loaded SharePoint Assemblies? May 18, 2015 at 13:11
  • Yes, I have. Now it works. Looks like I didn't have the correct permissions.
    – jlai
    May 19, 2015 at 6:37
  • Is it possible to sort the folders and file alphabetically?
    – jlai
    May 19, 2015 at 8:55

I know this is old, but others might find this question when looking it up. I figured out a very easy way:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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