You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python3中使用dirsync同步目录时,如何传递create参数创建目标目录?

解决dirsync同步时目标目录不存在的问题

直接在sync函数调用中添加create=True参数即可,该参数对应命令行的-c/--create选项,会自动创建不存在的目标目录。修改后的代码如下:

from dirsync import sync

source_name='directory2828_bkp20220524'
source_path = '/home/micky/'+source_name

target_path = '/mnt/backup_001/'+source_name
sync(source_path, target_path, 'sync', verbose=True, create=True) 

内容的提问来源于stack exchange,提问作者user22216550

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 11:24:51