Trying to get a portion of my script to work. This section will have the user define the web root so that we can run searches of that directory for malware. Here is the portion I am working on: I need to be able to get the user input and make it a variable to add to the search functions. I'm certain I'm going about this all wrong.

import os
for root in raw_input("Where is the web root? "):
    if os.path.isdir(root):
        print "Using %r" % (root)
    elif os.path.isdir(root):
        print "Directory not found."

I would like to have the script check the directory to make sure it exists (in case of typo), then continue and run searches for certain strings. Thanks!

有帮助吗?

解决方案

I guess you need a while loop here:

import os
root = raw_input("Where is the web root? "
while not os.path.isdir(root):
    print "Directory not found, try again"
    root = raw_input("Where is the web root? ")

print "Using %r" % (root)
#or do something else with root here
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top