使用Python列出NAS上的所有文件夹

2024-04-26 09:20:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python列出一个Synology NAS上的所有共享文件夹。在

假设我想要一个\\DISKSTATION
上每个文件夹的列表 例如:公共、家庭、电影等

有可能吗?在

谢谢你的帮助!在


Tags: 文件夹列表电影家庭nassynology试图用diskstation
3条回答
from smb.SMBConnection import SMBConnection

conn = SMBConnection('username', 'password', 'local_NetBIOS_name',   'remote_NetBIOS_name')
conn.connect('domain address')
folders = conn.listPath('share_name', '/relative/subfolder')

for folder in folders:
    print folder.filename

在连接也可以利用域地址xyz.com网站在

^{pr2}$

如果您可以直接访问NAS文件夹(无需进一步验证),则可以尝试运行python:

import os
os.listdir(r'\\DISKSTATION')

它将打印出\\DISKSTATION中的子文件夹。如果你想找到所有的子文件夹,你可以按照:Getting a list of all subdirectories in the current directory

为什么不使用pysmb?在

pip install pysmb

要列出共享内容:

^{pr2}$

将输出:

.
..
dir1
dir2
file1
file2

相关问题 更多 >