Check if file exists
This commit is contained in:
parent
cfba04ce20
commit
df00d36eca
1 changed files with 25 additions and 16 deletions
|
@ -1,4 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
import os.path
|
||||||
|
from os import path
|
||||||
|
import subprocess
|
||||||
|
|
||||||
class Multi():
|
class Multi():
|
||||||
|
|
||||||
|
@ -7,15 +10,18 @@ class Multi():
|
||||||
self.files = files
|
self.files = files
|
||||||
|
|
||||||
def print_matches(self):
|
def print_matches(self):
|
||||||
error = "Invalid input.\nExample: shellnotes -m pattern1,pattern2,pattern3 file1,file2,file3"
|
|
||||||
for pattern in self.patterns:
|
|
||||||
if pattern == "": return error
|
|
||||||
print(pattern, end=", ")
|
|
||||||
print()
|
|
||||||
for file in self.files:
|
|
||||||
if file == "": return error
|
|
||||||
print(file, end=", ")
|
|
||||||
|
|
||||||
|
for file in self.files:
|
||||||
|
if file == "": return 0
|
||||||
|
print(file if path.exists('Notes/'+file) else f"{file} (not found):\n-")
|
||||||
|
print("=" * len(file) if path.exists('Notes/'+file) else "")
|
||||||
|
|
||||||
|
for pattern in self.patterns:
|
||||||
|
if pattern == "": return 0
|
||||||
|
#run grep...
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
try:
|
try:
|
||||||
newMulti = Multi(sys.argv[1].split(','), sys.argv[2].split(','))
|
newMulti = Multi(sys.argv[1].split(','), sys.argv[2].split(','))
|
||||||
newMulti.print_matches()
|
newMulti.print_matches()
|
||||||
|
@ -25,3 +31,6 @@ except IndexError:
|
||||||
newMulti = Multi(patterns.split(','), files.split(','))
|
newMulti = Multi(patterns.split(','), files.split(','))
|
||||||
newMulti.print_matches()
|
newMulti.print_matches()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue