The following code searches a specific substring in all 'txt' file in a directory. ``` import os import time directory = 'D:/Python/file1/' for filename in os.listdir(directory): filesize = os.stat(filename).st_size if (filesize>60000): continue # print(filename) with open(filename, 'rb') as f: lines = f.readlines() for line in lines: tempstr = str(line) le = len(tempstr) #print(tempstr) findresults=tempstr.find("binance") #print(findresults) # time.sleep(5) if (findresults!=-1): print(filename) print(tempstr) ```
author | python-dev |
---|---|
permlink | search-substring-in-all-text-files-in-a-directory |
category | hive-107130 |
json_metadata | {"tags":["hive-107130","python-dev"],"app":"steemit/0.2","format":"markdown"} |
created | 2020-03-13 22:15:39 |
last_update | 2020-03-13 22:15:39 |
depth | 0 |
children | 0 |
last_payout | 2020-03-20 22:15:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.553 HBD |
curator_payout_value | 0.552 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 564 |
author_reputation | 5,457,648,648,750 |
root_title | "Search substring in all text files in a directory" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 0 |
post_id | 96,333,910 |
net_rshares | 4,278,937,331,767 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
anomaly | 0 | 151,649,647 | 1% | ||
mytechtrail | 0 | 38,733,787,193 | 20% | ||
xiguang | 0 | 1,596,078,914,884 | 100% | ||
ctime | 0 | 208,879,565,509 | 2% | ||
crypto.income | 0 | 2,435,093,414,534 | 100% |