File tree 1 file changed +43
-2
lines changed
1 file changed +43
-2
lines changed Original file line number Diff line number Diff line change 1
- # Python-Projects-Find-a-file-using-a-string
2
- Python Project: Find a file using a string
1
+ # Python Project: Find a file using a string 🐍
2
+
3
+ Python Script <br >
4
+ This repo contains python code that returns the path that contains the file with the string that you are searching for. <br >
5
+ Run the code.
6
+
7
+ Python
8
+ ```
9
+ import os
10
+
11
+ text = input("input text : ")
12
+
13
+ path = input("path : ")
14
+
15
+ # os.chdir(path)
16
+
17
+
18
+ def getfiles(path):
19
+ f = 0
20
+ os.chdir(path)
21
+ files = os.listdir()
22
+ # print(files)
23
+ for file_name in files:
24
+ abs_path = os.path.abspath(file_name)
25
+ if os.path.isdir(abs_path):
26
+ getfiles(abs_path)
27
+ if os.path.isfile(abs_path):
28
+ f = open(file_name, "r")
29
+ if text in f.read():
30
+ f = 1
31
+ print(text + " found in ")
32
+ final_path = os.path.abspath(file_name)
33
+ print(final_path)
34
+ return True
35
+
36
+ if f == 1:
37
+ print(text + " not found! ")
38
+ return False
39
+
40
+
41
+ getfiles(path)
42
+ ```
43
+
You can’t perform that action at this time.
0 commit comments