OneDrive同步电脑任意文件夹

要解决的OneDrive问题

OneDrive在国内熟读还能接受,主要是配合office365,使用非常方便,但是该软件仅可同步指定目录下的文件以及文件夹,我们不可能把所有要同步的文件先放进去在同步,此方法可解决非指定文件夹下的同步问题

可以使用建立符号连接的方式来达到制定文件夹同步的目的
譬如我要把E盘的学习文件文件夹同步到D盘OneDrive知道目录,那么,我可以

mklink /d D:\OneDrive\学习文件 E:\学习文件

注意,在D盘OneDrive文件夹里不需要创建名为学习文件的文件夹,系统会自动创建,否则不能成功
若路径含有非法字符则可

mklink /d D:\OneDrive\学习文件 “E:\学习文件”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Python中的schedule模块和onedrive模块来实现定时抓取onedrive文件到本地文件夹。 首先需要安装schedule和onedrive模块,可以使用以下命令进行安装: ``` pip install schedule pip install onedrive-sdk-python ``` 接下来,你需要获得onedrive的API凭证,具体步骤可以参考Microsoft官方文档:https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/app-registration?view=odsp-graph-online 获取到API凭证后,你可以使用以下代码实现定时抓取onedrive文件到本地文件夹: ```python import schedule import time import os from onedrivesdk import ( OneDriveClient, http, AuthProvider ) # 定义抓取间隔时间(秒) INTERVAL = 60 * 10 # 定义本地文件夹路径和要抓取的onedrive文件路径 LOCAL_FOLDER_PATH = "D:/onedrive_files" ONEDRIVE_FILE_PATH = "/Documents/file.txt" # 定义onedrive API凭证信息 CLIENT_ID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' REDIRECT_URI = 'http://localhost:8080' REFRESH_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # 初始化auth_provider和client auth_provider = AuthProvider( client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI, refresh_token=REFRESH_TOKEN ) client = OneDriveClient(auth_provider=auth_provider) def download_file(): # 获取onedrive文件的下载链接 item = client.item(path=ONEDRIVE_FILE_PATH) download_url = client.item(drive='me', id=item.id).get('@microsoft.graph.downloadUrl') # 下载文件到本地文件夹 response = http.get(download_url) file_name = os.path.basename(ONEDRIVE_FILE_PATH) with open(os.path.join(LOCAL_FOLDER_PATH, file_name), "wb") as f: f.write(response.content) print("File downloaded successfully!") schedule.every(INTERVAL).seconds.do(download_file) while True: schedule.run_pending() time.sleep(1) ``` 以上代码定义了定时抓取间隔时间、本地文件夹路径、要抓取的onedrive文件路径以及API凭证信息。在`download_file`函数中,首先使用`client.item`方法获取onedrive文件的信息,然后使用`client.item(drive='me', id=item.id).get('@microsoft.graph.downloadUrl')`方法获取文件的下载链接,最后使用`http.get`方法下载文件到本地文件夹。 如果你想要抓取其他类型的文件,只需要将`ONEDRIVE_FILE_PATH`更改为相应的路径即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值