【问题标题】:How to include option in dirsync python module?如何在 dirsync python 模块中包含选项?
【发布时间】:2018-12-10 21:16:01
【问题描述】:

我有 Python 版本 3.7.1。

我想将源目录中扩展名为 .835 的文件同步到目标目录。为什么这段代码会拉取所有文件?

import dirsync
dirsync.sync(source,destination,'sync',verbose=True,only='.*\.835$')

我也尝试过这样的 --include 选项和模式:

import dirsync
pattern = r'.*\.835$'
dirsync.sync(source,destination,'sync',verbose=True,include=pattern)

我该如何解决这个问题?

【问题讨论】:

  • 你的模式没有问题。这个问题一定与目录同步有关

标签: regex python-3.x


【解决方案1】:

尝试在正则表达式后添加逗号:

import dirsync
pattern = r'.*\.835$',
dirsync.sync(source, destination, 'sync', verbose=True, include=pattern)

或:

import dirsync
dirsync.sync(source, destination, 'sync', verbose=True, include=(r'^.*\.wav$',))

如果您仍然遇到问题,目录同步示例脚本应该为您指明正确的方向:https://bitbucket.org/tkhyn/dirsync/src/default/tests/regexfilters.py

我还会确保您知道各种选项的作用。根据用例,“only”可能比“include”更有用

您可以在此处找到文档:https://bitbucket.org/tkhyn/dirsync/src/default/

--only, -o 模式

要包含的正则表达式模式(排除所有其他模式)

--排除,-e 模式

要排除的正则表达式模式

--include, -i 模式

要包含的正则表达式模式(优先于排除)

【讨论】:

    猜你喜欢
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 2013-10-28
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    相关资源
    最近更新 更多