搜索整个文件夹而不是文件python

时间:2016-02-03 17:00:34

标签: python

如何从整个文件夹而不是简单文件中搜索?

class ProductRequestTableViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    var profileImage = ["image1","image2"]
    var userName = ["john doe","john doe"]
    var requestTitle = ["lorem ipsum lorem ipsum.","I have a Wordpress website and I am looking for someone to create a landing page with links and a cart to link up"]
    var date = ["Feb 03, 16","Feb 03, 16"]

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        // #warning Incomplete implementation, return the number of rows
        return profileImage.count
    }


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {



        if(indexPath.row==0){
            let cell = tableView.dequeueReusableCellWithIdentifier("firstCustomCell", forIndexPath: indexPath) as! FirstProductRequestTableViewCell

            cell.userNameLabel.text = userName[indexPath.row]
            cell.profileImage.image = UIImage(named: profileImage[indexPath.row])
            return cell

        }else{




            let cell = tableView.dequeueReusableCellWithIdentifier("secondCustomCell", forIndexPath: indexPath) as! SecondProductRequestTableViewCell

           cell.requestTitleTxtView.text = requestTitle[indexPath.row]
            return cell

                  }
           }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        print(indexPath.row)


    }

    // Override to support conditional editing of the table view.
    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }



    // Override to support editing the table view.
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }
    }



    // Override to support rearranging the table view.
    func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }



    // Override to support conditional rearranging of the table view.
    func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }

1 个答案:

答案 0 :(得分:0)

此问题似乎与Trying to find specific words from all files in a directory using python基本相同。

在那篇文章中,我试图逐步展示如何将代码更改为可以执行所要求的内容。

所以,在这里,我只是展示我的最终解决方案:

from os import system, listdir, path
system("cls")
system("color b9")
FILE = open("CodeR.txt", "a")
desktop_dir = r"C:\Users\ilan\Desktop"
for fn in listdir(desktop_dir):
    fn_w_path = path.join(desktop_dir, fn)
    if path.isfile(fn_w_path):
        with open(fn_w_path) as filee:
            for line in filee:
                for word in line.lower().split():
                    if word in {"user", "password", "username", "pass",
                                "secret", "key", "backdoor", "ip"}:
                        FILE.write(word + "\n")
FILE.close()

并在其他帖子中将任何读者推荐到我的answer以获取更多信息/解释。

〜罗素

P.S。 - Roland Smith向另一个帖子提供alternate solution,这在技术上似乎优于我的。但是,对于相对缺乏Python经验的人来说,理解它可能并不容易。