forked from ActionSeeker/chatbot-using-nlp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilecheck.py~
56 lines (52 loc) · 1.41 KB
/
filecheck.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
54
55
56
import os
from decimal import Decimal
def checkIfInHome(fileName):
k = os.getcwd() #saves the current working directory
os.system('cd /home')
os.system('find /home -type f -name '+fileName+' 2>/dev/null |cat>temp')
f = open('temp','r')
fileSet = set()
for line in f:
if 'Permission denied' not in line:
fileSet.add(line.rstrip('\n'))
fileSet = list(fileSet)
return fileSet
def checkIfInHomeDir(dirName):
k = os.getcwd() #saves the current working directory
os.system('cd /home')
os.system('find /home -type d -name '+dirName+' 2>/dev/null |cat>temp')
f = open('temp','r')
dirSet = set()
for line in f:
if 'Permission denied' not in line:
dirSet.add(line.rstrip('\n'))
dirSet = list(dirSet)
return dirSet
def isFileName(userName,fileName):
os.system('find /home/'+userName+' -type f -name '+fileName+' 2>/dev/null |cat>temp')
os.system('wc -l<temp >count')
countL=''
f = open('count','r')
for line in f:
countL = line.strip('\n')
countL = Decimal(countL)
os.system('rm temp')
os.system('rm count')
if countL>=1:
return True
else:
return False
def isDirName(userName,fileName):
os.system('find /home/'+userName+' -type d -name '+fileName+' 2>/dev/null |cat>temp')
os.system('wc -l<temp >count')
countL=''
f = open('count','r')
for line in f:
countL = line.strip('\n')
countL = Decimal(countL)
os.system('rm temp')
os.system('rm count')
if countL>=1:
return True
else:
return False