Answers for "python search file for string in a folders"

1

python find file in directory

# option A (i think this is faster, not in micropython)

import os

if os.path.isfile("test.dat"):
	print("yes") #file found
else:
	print("no") #file not found

# also this is posible
# from os.path import isfile
# if isfile("test.dat"):


# option B (posible in micropython)

import os

if "test.dat" in os.listdir():
	print("yes") # file found
else:
	print("no") # file not found

# os.lisdir() return a array whit all the files found in the directory
Posted by: Guest on March-29-2021
-1

python search all txts in a folder

index_file =  open('index.txt', 'r')
    for line in index_file:
       ....
Posted by: Guest on December-12-2020

Code answers related to "python search file for string in a folders"

Python Answers by Framework

Browse Popular Code Answers by Language