gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 00:48:24 24 4
gpt4 key购买 nike

我有 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)
我该如何解决这个问题?

最佳答案

尝试在您的正则表达式后添加一个逗号:

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 模式

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

关于regex - 如何在 dirsync python 模块中包含选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53713764/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com