File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Script Name : check_file.py
2
+ # Author : Craig Richards
3
+ # Created : 20 May 2013
4
+ # Last Modified :
5
+ # Version : 1.0
6
+
7
+ # Modifications :
8
+
9
+ # Description : Check a file exists and that we can read the file
10
+
11
+ import sys # Import the Modules
12
+ import os # Import the Modules
13
+
14
+ # Readfile Functions which open the file that is passed to the script
15
+
16
+ def readfile (filename ):
17
+ f = open (filename , 'r' )
18
+ line = f .read ()
19
+ print line
20
+
21
+ def main ():
22
+ if len (sys .argv ) == 2 : # Check the arguments passed to the script
23
+ filename = sys .argv [1 ] # The filename is the first argument
24
+ if not os .path .isfile (filename ): # Check the File exists
25
+ print '[-] ' + filename + ' does not exist.'
26
+ exit (0 )
27
+ if not os .access (filename , os .R_OK ): # Check you can read the file
28
+ print '[-] ' + filename + ' access denied'
29
+ exit (0 )
30
+ else :
31
+ print '[-] Usage: ' + str (sys .argv [0 ]) + ' <filename>' # Print usage if not all parameters passed/Checked
32
+ exit (0 )
33
+ print '[+] Reading from : ' + filename # Display Message and read the file contents
34
+ readfile (filename )
35
+
36
+ if __name__ == '__main__' :
37
+ main ()
You can’t perform that action at this time.
0 commit comments