file_path中的路径中有两个日志,我想使用python读取它们

发布于 2025-02-07 16:42:13 字数 494 浏览 1 评论 0原文

D:\编码\ iRoiro \ chuckrep文件夹中有a,b,c,d的文件夹,其中还有e,f,g,h hh folder。并且在此E,F,G,H文件夹中有C000日志和W日志,我想单独将它们带入其中,但是我不知道我设计的代码是错误的还是什么都不是。

file_path = './ChuckRep/*/*/'
file_name, ext = os.path.splitext(file_path)

for path in glob.glob(file_path):
    if ext=='.smm_logs':
        cfile_path = glob.glob(file_name[:-4]+'C000.smm_logs')[0]
        wfile_paths = glob.glob(file_name[:-4]+'*W*.smm_logs')
        print(cfile_path)
    


如何打印cfile_path和wfile_path以获取结果?

There are a,b,c,d folders in the D:\Coding\iroiro\ChuckRep folder, and there are also e,f,g,h folders in it. And there are C000 logs and W logs in this e,f,g,h folder, and I want to bring them in individually, but I don't know if the code I designed is wrong or nothing.

file_path = './ChuckRep/*/*/'
file_name, ext = os.path.splitext(file_path)

for path in glob.glob(file_path):
    if ext=='.smm_logs':
        cfile_path = glob.glob(file_name[:-4]+'C000.smm_logs')[0]
        wfile_paths = glob.glob(file_name[:-4]+'*W*.smm_logs')
        print(cfile_path)
    


How can I print cfile_path and wfile_path to get the result?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懵少女 2025-02-14 16:42:13
  1. 如果您展开file_path类似glob的,则只会获得目录。
  2. 您尝试在扩展之前将扩展名与Glot Pattern String分开,这是没有意义的。
  3. 相反,我建议您从使用 os.walk()< /code>,我会说这对初学者而言不那么困惑。
  1. If you expand your file_path glob-like, you get only directories.
  2. You try to split extension from a glob pattern string before expansion, which doesn't make sense.
  3. Instead I suggest you start with using os.walk(), I'd say it's less confusing for beginner.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文