简体   繁体   English

我不知道如何获取此脚本以将受感染文件的列表打印到输出文件

[英]I can't figure out how to get this script to print a list of infected files to an output file

I have this antivirus assignment to find a specific virus SigData = Infected . 我已为此防病毒任务找到了特定的病毒SigData = Infected I am lost on how to finish this script to get it to print a list of infected files to an output file. 我不知道如何完成此脚本,以使其将受感染文件的列表打印到输出文件。

I tried os.listdir(path) , but it says the path is not defined. 我尝试了os.listdir(path) ,但是它说未定义路径。 I don't know how else to print the list I need from this code: 我不知道如何从此代码打印我需要的列表:

import os
import inspect
SigData="Infected"


def search(path): #Searches for files in path.
    filestodisinfect = []
    filelist = os.listdir(path)
    for filename in filelist:
        if os.path.isdir(path+"/"+filename): #Looks for folder
            filestodisinfect.extend(search(path+"/"+filename))
        elif filename[-3:] == ".py": #Searches for python scripts to disinfect
            for line in open(path+"/"+filename):
                if SigData in line:
                    if infected == True:
                        filestodisinfect.append(path+"/"+filename)
    return filestodisinfect

I expect this script to find the virus from it's sigdata, which I have done, but need it to print a list of the infected files to an output file. 我希望此脚本能够从sigdata中找到病毒,这已经完成了,但是需要它来将感染文件列表打印到输出文件中。

I used this: 我用这个:

mylist=('')
myfile=open('output.txt','w') #Creates file to save list
for item in mylist:
    print >>myfile, item
myfile.close()

It created an output txt file, but it won't put the infected files to that file? 它创建了一个输出txt文件,但是不会将受感染的文件放到该文件中吗? How can I achieve that from this. 我怎样才能做到这一点。 Sorry guys I'm new to python and suck. 抱歉,我是python和吮吸的新手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM