Skip to content

0x05 操作文件(夹)

zaxtyson edited this page Mar 2, 2021 · 2 revisions

.delete(fid, is_file)

把网盘的文件(夹)放入回收站

参数 类型 说明 必填 备注
fid int 文件(夹)id Y -
is_file bool 是否为文件id N 默认True

示例 :

>>> lzy.delete(12741016) == LanZouCloud.SUCCESS
True

返回值 :

  • 成功返回 : LanZouCloud.SUCCESS
  • 失败返回 : LanZouCloud.FAILED
  • 网络异常 : LanZouCloud.NETWORK_ERROR

注意 :

  • 无法删除含有子文件夹的文件夹,但含有文件的可以删除。
  • 重复删除同一个 id 仍返回 : LanZouCloud.SUCCESS
  • 删除不存在的 id 也返回 : LanZouCloud.SUCCESS

.move_file(file_id, folder_id)

移动文件到指定文件夹

参数 类型 说明 必填 备注
file_id int 文件id Y -
folder_id int 文件夹id N 默认-1(根目录)

示例 :

# 移动文件(id=12741016) 到文件夹(id=1037083)
>>> lzy.move_file(12741016, 1037083) == LanZouCloud.SUCCESS
True

返回值 :

  • 成功返回 : LanZouCloud.SUCCESS
  • 失败返回 : LanZouCloud.FAILED
  • 网络异常 : LanZouCloud.NETWORK_ERROR

注意: 不能移动文件到原始位置(未发生移动)


.move_folder(folder_id, parent_folder_id)

移动文件夹到指定文件夹

参数 类型 说明 必填 备注
folder_id int 文件夹id Y -
parent_folder_id int 目标文件夹id N 默认-1(根目录)

示例 :

# 移动文件夹(id=1384074)到文件夹(id=879591)内
>>> lzy.move_folder(1384074, 879591 ) == LanZouCloud.SUCCESS
True

返回值 :

  • 成功返回 : LanZouCloud.SUCCESS
  • 失败返回 : LanZouCloud.FAILED
  • 网络异常 : LanZouCloud.NETWORK_ERROR

注意:

  • 不能移动文件夹到其自身,不能移动到原始位置。
  • 不能存在子文件夹,蓝奏云限制的文件夹深度为 4 层,通过递归调用移动文件夹时可能会超过限制导致错误。
  • 官方并没有提供移动文件夹的接口,本函数做的操作是:在目标文件夹下创建同名文件夹,设置相同的描述信息和密码,移动原文件夹下的所有文件,删除原文件夹。

.mkdir(parent_id, folder_name, desc)

创建文件夹并返回 id

参数 类型 说明 必填 备注
parent_id int 父文件夹id Y -1 表根目录
folder_name str 文件夹名 Y 自动删除非法字符
desc str 文件夹描述 N 默认无

示例 :

>>> fid = lzy.mkdir(-1, 'my_music', '音乐分享')
>>> fid == LanZouCloud.MKDIR_ERROR
False

>>> fid
1451842

返回值 :

  • 创建成功返回: 文件夹ID
  • 目标已存在返回: 文件夹ID
  • 创建失败返回: LanZouCloud.MKDIR_ERROR

.rename_file(file_id, file_name)

支持会员用户重命名文件

参数 类型 说明 必填 备注
file_id int 文件id Y -
file_name str 文件名 Y 非法字符自动删除

示例 :

>>> lzy.rename_file(10900827, '鸡*你太美%') == LanZouCloud.SUCCESS
True

返回值 :

  • 修改成功 : LanZouCloud.SUCCESS
  • 修改失败 : LanZouCloud.FAILED
  • 网络异常 : LanZouCloud.NETWORK_ERROR

.rename_dir(folder_id, folder_name)

重命名文件夹

参数 类型 说明 必填 备注
folder_id int 文件夹id Y -
folder_name str 文件夹名 Y 非法字符自动删除

示例 :

>>> lzy.rename_dir(1037070, 'soft_music') == LanZouCloud.SUCCESS
True

返回值 :

  • 修改成功 : LanZouCloud.SUCCESS
  • 修改失败 : LanZouCloud.FAILED
  • 网络异常 : LanZouCloud.NETWORK_ERROR

.set_desc(fid, desc, is_file)

修改文件(夹)描述信息

参数 类型 说明 必填 备注
fid int 文件(夹)id Y -
desc str 描述内容 Y -
is_file bool 是否为文件id N 默认True

示例 :

>>> lzy.set_desc(1083604, '批量上传的音乐', is_file=False) == LanZouCloud.SUCCESS
True

返回值 :

  • 修改成功 : LanZouCloud.SUCCESS
  • 修改失败 : LanZouCloud.FAILED
  • 网络异常 : LanZouCloud.NETWORK_ERROR

注意 :

  • 文件描述一旦设置,不允许再次置空
  • 文件夹描述可以置空

.set_passwd(fid, passwd, is_file)

设置文件(夹)提取码

参数 类型 说明 必填 备注
fid int 文件(夹)id Y -
passwd str 分享密码 N 默认空(无密码)
is_file bool 是否为文件id N 默认True

示例 :

>>> lzy.set_share_info(1033203, 'fuck') == LanZouCloud.SUCCESS
True

返回值 :

  • 设置成功 : LanZouCloud.SUCCESS
  • 设置失败 : LanZouCloud.FAILED
  • 网络异常 : LanZouCloud.NETWORK_ERROR

注意 :

  • 文件夹提取码长度 2-12 位(置空关闭),文件提取码 2-6 位(置空关闭)
  • 创建文件夹会随机产生一个提取码, 创建文件不会
  • 现在非 VIP 用户无法关闭提取码!