如何在dirsync python模块中包含选项?

时间:2018-12-10 21:16:02

标签: regex python-3.x

我有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)

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

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

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

我还要确保您知道各种选项的作用。根据使用情况,“仅”可能比“包含”更有用

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

-仅-o模式

要包含的正则表达式模式(彼此排除)

-排除,-e模式

要排除的正则表达式模式

-包括-i模式

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