How to list all files inside the folder of sharepoint using python

Viewed 7122

I'm currently using shareplum and was able to do the download thing using this code below:

from shareplum import Site
from shareplum import Office365
from shareplum.site import Version
import csv


authcookie = Office365('https://bboxxeng.sharepoint.com/', username='---', password='---').GetCookies()
site = Site('https://bboxxeng.sharepoint.com/sites/TESTIAN', version=Version.v2016, authcookie=authcookie)
folder = site.Folder('Shared%20Documents/Test')
data = folder.get_file('Office ss E1.csv')
with open('asas.csv', 'wb') as f:
   f.write(data)
   f.close()

I tried using list_data = sp_list.GetListItems() but have no luck extracting the file names, I've also ready and tried googling but still no luck.

1 Answers

I understand you want to list all files in a folder so that you can download or do other modification via the file name. If so, you can get it via below attrbutes:

files

folder = site.Folder('Shared Documents/test')

allfiles= folder.files

print(allfiles)

enter image description here

//////////// Updated //////

The result contains file name and other properties.

enter image description here

For example, i want to get the name of first file from the returned result.

allfiles= folder.files
demofile= allfiles[0]
print(demofile['Name'])
Related