首页 > 其他分享 >Pyhon|Aligo|右键上传阿里云盘

Pyhon|Aligo|右键上传阿里云盘

时间:2022-11-10 00:33:52浏览次数:72  
标签:__ ali Pyhon Aligo 右键 file folder local

资料

项目:https://github.com/foyoux/aligo
教程:https://www.cnblogs.com/foyou/p/15094643.html

安装模块

pip install aligo -i https://pypi.tuna.tsinghua.edu.cn/simple

单文件上传到根目录

from aligo import Aligoali = Aligo()
local_file = r"D:\图片\birds.png"
up_file = ali.upload_file(local_file)

单文件上传到指定目录

from aligo import Aligo
ali = Aligo()
remote_folder = ali.get_folder_by_path('FromPython')
local_file = r"D:\图片\birds.png"
up_file = ali.upload_file(local_file, parent_file_id=remote_folder.file_id)

文件夹上传到根目录

from aligo import Aligo
if __name__ == '__main__':
	ali = Aligo()
	# 本地目录
	local_folder = r'D:\File_VS\C_CPP\EXE_Qt\Test\Debug\Test.tlog'
	# 上传
	ali.upload_folder(local_folder)

文件夹上传到指定目录

from aligo import Aligo
if __name__ == '__main__':
	ali = Aligo()
	# 云盘中的目录
	remote_folder = ali.get_folder_by_path('paper/001')
	# 本地目录
	local_folder = r'D:\File_VS\C_CPP\EXE_Qt\Test\Debug\Test.tlog'
	# 上传
	ali.upload_folder(local_folder, parent_file_id=remote_folder.file_id)

文件(夹)右键上传

文件右键,文件上右键,文件名传递,参数传递,python参数传递,bat参数传递

基于Python把文件拖到bat文件上操作文件

002.bat文件内容:

"C:\Xdd\software\python39\python.exe" "F:\Download\001.py" -F %1

001.py文件内容

# 001.py
import argparse

def paeseSet()
	parser = argparse.ArgumentParser(description="参数设置")
	parser.add_argument('-F', '--file',help='文件路径')
	args = parser.parse_args()
	return
def main():
	args = paeseSet()
	filePath = args.file
	with open(r"F:\Download\ddx199758.txt",'w') as fw:
		fw.write(filePath)
if __name__ == '__main__':
	main()

文件右键运行python程序操作文件- 添加到桌面右键的注册表

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Aliyun]
"Icon"="C:\\ImportantFile_Xdd\\AliYun\\aliyun.ico"
[HKEY_CLASSES_ROOT\*\shell\Aliyun\command]
@="C:\\ImportantFile_Xdd\\AliYun\\Aliyun.bat %L"

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Aliyun]
"Icon"="C:\\\\ImportantFile_Xdd\\\\AliYun\\\\aliyun.ico"
[HKEY_CLASSES_ROOT\Directory\shell\Aliyun\command]
@="C:\\\\ImportantFile_Xdd\\\\AliYun\\\\Aliyun.bat %L"
import os
import argparse
from aligo import Aligo
def paeseSet():
	parser = argparse.ArgumentParser(description="参数设置")
	parser.add_argument('-F', '--file',help='文件路径')
	args = parser.parse_args()

	return args
	
def main():
	args = paeseSet()
	local_f = args.file
	ali = Aligo()
	remote_folder = ali.get_folder_by_path('FromPython')
	if remote_folder is None:
		remote_folder = ali.create_folder('FromPython')
		remote_folder = ali.get_folder_by_path('FromPython')
	if os.path.isdir(filePath):
		ali.upload_folder(local_f, parent_file_id=remote_folder.file_id)
	else:
		up_file = ali.upload_file(local_f, parent_file_id=remote_folder.file_id)
		
if __name__ == '__main__':
main()

感谢

 

标签:__,ali,Pyhon,Aligo,右键,file,folder,local
From: https://www.cnblogs.com/xdd1997/p/16875703.html

相关文章