简体   繁体   中英

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

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.

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)

在此处输入图像描述

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

The result contains file name and other properties.

在此处输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM