Variable passing to external program - How??
Cousin Stanley
CousinStanley at hotmail.com
Sat Oct 11 13:17:15 EDT 2003
Following is yet another version for checking file access
that takes the file_path as an argument to the module,
and differentiates R,E,W or NO access ....
'''
Module ....... os_file_access.py
NewsGroup .... comp.lang.python
Date ......... 2003-10-10
Posted_By .... rigga
Edited_By .... Stanley C. Kitching
'''
import os
import sys
NL = '\n'
SP = ' '
SP3 = SP * 3
SP7 = SP * 7
module_this = sys.argv[ 0 ]
print '%s %s ' % ( NL , module_this ) , NL
if len( sys.argv ) < 2 :
print SP7 , 'Usage : python os_file_access.py file_path' , NL
sys.exit( -1 )
file_path = sys.argv[ 1 ] # Input File Path as 1st Argument
if os.path.exists( file_path ) :
print SP7 , "File Path Exists ...." , file_path , NL
read_flag = os.access( file_path , os.R_OK )
exec_flag = os.access( file_path , os.X_OK )
write_flag = os.access( file_path , os.W_OK )
else :
print SP7 , "*** File NOT Found ***" , NL
print SP7 , SP3 , file_path , NL
sys.exit( -2 )
list_access = []
if read_flag : list_access.append( 'Read' )
if exec_flag : list_access.append( 'Execute' )
if write_flag : list_access.append( 'Write' )
if ( read_flag | exec_flag | write_flag ) :
str_access = ' , '.join( list_access )
else :
str_access = 'NO'
print SP7 , 'You have [ %s ] Access to the File' % ( str_access ) , NL
--
Cousin Stanley
Human Being
Phoenix, Arizona
More information about the Python-list
mailing list