Python错误os.walk IOError

用户名

我试图用文件名中的服务器跟踪文件,并且可以使用服务器**来打印目录中的所有文件,但是当我尝试读取文件时,它给了我错误提示:

Traceback (most recent call last):
  File "view_log_packetloss.sh", line 27, in <module>
    with open(filename,'rb') as files:
IOError: [Errno 2] No such file or directory: 'pcoip_server_2014_05_19_00000560.txt'

我看到有人问过类似的问题,但我无法解决我的问题,使用chdir将当前目录更改为文件目录已修复了一些错误。任何帮助表示赞赏。谢谢

#!usr/bin/env/ python
import sys, re, os

#fucntion to find the packetloss data in pcoip server files
def function_pcoip_packetloss(filename):
        lineContains = re.compile('.*Loss=.*')  #look for "Loss=" in the file
        for line in filename:
                if lineContains.match(line):    #check if line matches "Loss="
                        print 'The file has: '  #prints if "Loss=" is found
                        print line
                        return 0;

for root, dirs, files in os.walk("/users/home10/tshrestha/brb-view/logs/vdm-sdct-agent/pcoip-logs"):
        lineContainsServerFile = re.compile('.*server.*')
        for filename in files:
                if lineContainsServerFile.match(filename):
                        with open(filename,'rb') as files:
                                print 'filename'
                                function_pcoip_packetloss(filename);
go1dshtein

这些文件是根目录中文件对象的名称。

dirpath是一个字符串,是目录的路径。dirnames是dirpath中子目录名称的列表(不包括“。”和“ ..”)。filenames是dirpath中非目录文件名称的列表。请注意,列表中的名称不包含路径成分。要获取目录路径中文件或目录的完整路径(从顶部开始),请执行os.path.join(dirpath,name)。

尝试这个

for root, dirs, files in os.walk("/users/home10/tshrestha/brb-view/logs/vdm-sdct-agent/pcoip-logs"):
    lineContainsServerFile = re.compile('.*server.*')
    for filename in files:
            if lineContainsServerFile.match(filename):
                    filename = os.path.join(root, filename)
                    with open(filename,'rb') as files:
                            print 'filename:', filename
                            function_pcoip_packetloss(filename);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Python error os.walk IOError

来自分类Dev

IOError: [Errno 2] 没有那个文件或目录 – os.walk

来自分类Dev

Python中的“ IOError:[Errno 0]错误”错误

来自分类Dev

Python os.walk()失败

来自分类Dev

Python os.walk()方法

来自分类Dev

未处理stopIteration的os.walk错误

来自分类Dev

未处理stopIteration的os.walk错误

来自分类Dev

os.walk() 错误 - 解包的值太多

来自分类Dev

Python:获取WindowsError而不是IOError

来自分类Dev

Python 3 OS Walk Unicode异常

来自分类Dev

遍历Python的os.walk()混乱

来自分类Dev

Python - recursive directory hit with os.walk()

来自分类Dev

Python os.walk和符号链接

来自分类Dev

遍历Python的os.walk()混乱

来自分类Dev

IOError:[错误5]输入/输出错误

来自分类Dev

Mac OS X上的Python posxifile.lock()IOError

来自分类Dev

多重处理IOError:错误的讯息长度

来自分类Dev

IOError:使用BeautifulSoup的[Errno套接字错误]

来自分类Dev

os.walk()不会在Python中引发任何错误或结果

来自分类Dev

Python中的time.sleep()奇怪的IOError

来自分类Dev

Python IOError,无法在目录中找到文件

来自分类Dev

尝试'open()',但Python for循环中的IOError除外

来自分类Dev

使用os.walk后,join抛出startswitherror错误

来自分类Dev

Python中os.walk的时间复杂度

来自分类Dev

Python os.walk()变音u'\ u0308'

来自分类Dev

没有os.walk的Python递归目录读取

来自分类Dev

以Python os.walk为例的递归定义

来自分类Dev

Python os.walk是否支持Unicode / UTF-8?

来自分类Dev

python3:os.walk有问题