Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 02-file-search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/opt/anaconda3/bin/python3

## Modules
import pathlib
import argparse

## Function
def file_search(dir,file):
try:
if dir.is_dir():
#print("Directory exists")
if file.is_file():
print("The file %s exist in the %s directory" %(args.arg2,args.arg1))
else:
print("The dir %s exist but the file %s is not in the directory" %(args.arg1,args.arg2))
else:
print("The directory %s doesnt exist" %args.arg1)
except:
print("Something went wrong")


## Create the parser
parser = argparse.ArgumentParser()

## Add the arguments
parser.add_argument("arg1", help="Directory Name")
parser.add_argument("arg2", help="File Name to search for in the dir")

## Execute the parse_arg() method
args = parser.parse_args()

dir = pathlib.Path(args.arg1)
file = pathlib.Path(args.arg1,args.arg2)

file_search(dir,file)