|
17 | 17 | import time |
18 | 18 |
|
19 | 19 | try_count = 16 |
| 20 | + |
20 | 21 | while try_count: |
21 | 22 | file_name = raw_input("Enter a file name: ") # pick a file you have |
22 | 23 | try_count >>= 1 |
|
29 | 30 | if try_count == 0: |
30 | 31 | print ("Trial limit exceded \nExiting program") |
31 | 32 | sys.exit() |
| 33 | + |
32 | 34 | # create a dictionary to hold file info |
33 | 35 | file_info = { |
34 | 36 | 'fname': file_name, |
35 | 37 | 'fsize': file_stats[stat.ST_SIZE], |
36 | | - 'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p", |
37 | | - time.localtime(file_stats[stat.ST_MTIME])), |
38 | | - 'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p", |
39 | | - time.localtime(file_stats[stat.ST_ATIME])), |
40 | | - 'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p", |
41 | | - time.localtime(file_stats[stat.ST_CTIME])) |
| 38 | + 'f_lm' : time.strftime("%d/%m/%Y %I:%M:%S %p", |
| 39 | + time.localtime(file_stats[stat.ST_MTIME])), |
| 40 | + 'f_la' : time.strftime("%d/%m/%Y %I:%M:%S %p", |
| 41 | + time.localtime(file_stats[stat.ST_ATIME])), |
| 42 | + 'f_ct' : time.strftime("%d/%m/%Y %I:%M:%S %p", |
| 43 | + time.localtime(file_stats[stat.ST_CTIME])) |
42 | 44 | } |
43 | 45 |
|
44 | | -print |
45 | | -print ("file name = %(fname)s", file_info) |
| 46 | +print ("\nfile name = %(fname)s", file_info) |
46 | 47 | print ("file size = %(fsize)s bytes", file_info) |
47 | 48 | print ("last modified = %(f_lm)s", file_info) |
48 | 49 | print ("last accessed = %(f_la)s", file_info) |
49 | | -print ("creation time = %(f_ct)s", file_info) |
50 | | -print |
51 | | -if stat.S_ISDIR(file_stats[stat.ST_MODE]): |
| 50 | +print ("creation time = %(f_ct)s\n", file_info) |
52 | 51 |
|
| 52 | +if stat.S_ISDIR(file_stats[stat.ST_MODE]): |
53 | 53 | print ("This a directory") |
54 | 54 | else: |
55 | | - print ("This is not a directory") |
56 | | - print () |
| 55 | + print ("This is not a directory\n") |
57 | 56 | print ("A closer look at the os.stat(%s) tuple:" % file_name) |
58 | 57 | print (file_stats) |
59 | | - print () |
60 | | - print ("The above tuple has the following sequence:") |
| 58 | + print ("\nThe above tuple has the following sequence:") |
61 | 59 | print ("""st_mode (protection bits), st_ino (inode number), |
62 | 60 | st_dev (device), st_nlink (number of hard links), |
63 | 61 | st_uid (user ID of owner), st_gid (group ID of owner), |
|
0 commit comments