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

use*_*182 5 regex python-3.x

我有 python 版本 3.7.1。

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

import dirsync
dirsync.sync(source,destination,'sync',verbose=True,only='.*\.835$')
Run Code Online (Sandbox Code Playgroud)

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

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

我该如何解决这个问题?

小智 3

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

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

或者:

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

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

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

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

--only, -o 模式

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

--排除,-e 模式

要排除的正则表达式模式

--include, -i 模式

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