create account

Search substring in all text files in a directory by python-dev

View this thread on: hive.blogpeakd.comecency.com
· @python-dev ·
$1.11
Search substring in all text files in a directory
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)
```
👍  , , , ,
properties (23)
authorpython-dev
permlinksearch-substring-in-all-text-files-in-a-directory
categoryhive-107130
json_metadata{"tags":["hive-107130","python-dev"],"app":"steemit/0.2","format":"markdown"}
created2020-03-13 22:15:39
last_update2020-03-13 22:15:39
depth0
children0
last_payout2020-03-20 22:15:39
cashout_time1969-12-31 23:59:59
total_payout_value0.553 HBD
curator_payout_value0.552 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length564
author_reputation5,457,648,648,750
root_title"Search substring in all text files in a directory"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id96,333,910
net_rshares4,278,937,331,767
author_curate_reward""
vote details (5)