-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_search.py
53 lines (39 loc) · 1.09 KB
/
file_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/python
'''
Author: Nathaniel
-------------------------------------------------------------------------------
Python version: 3.8.5
Script Usage: scans directory for matching files. Input string via command line
-------------------------------------------------------------------------------
'''
import os
import sys
curr_dir = os.getcwd()
string_input = sys.argv[1]
#compares string lengths
def compare_len(str_in, str_dir):
flag = True
if str_in > str_dir:
flag = False
return flag
#checks user string versus director string files
def file_check(str_in, str_dir):
flag = False
str_len = len(str_in)
str_dir_len = len(str_dir)
string_in = list(str_in)
string_dir = list(str_dir)
for i in range(0, str_len, 1):
if string_in[i] == string_dir[i] and compare_len(str_len, str_dir_len):
flag = True
else:
flag = False
break
return flag
#scans directory for all files listed
def dir_scan():
for file in os.listdir(curr_dir):
if file_check(string_input, file):
print(file)
#calls dir_scan to start script
dir_scan()