-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileTimeTest.py
73 lines (66 loc) · 2.39 KB
/
FileTimeTest.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
import os
import getpass
import time
try:
import tkinter as tk
from tkinter import filedialog
btKinterOK = True
except:
print ("Failed to load tkinter, CLI only mode.")
btKinterOK = False
# End imports
def getInput(strPrompt):
if sys.version_info[0] > 2 :
return input(strPrompt)
else:
return raw_input(strPrompt)
# end getInput
print ("Welcome to my Python Test script. Your username is {3}. This is running under Python Version {0}.{1}.{2}".format(sys.version_info[0],sys.version_info[1],sys.version_info[2],getpass.getuser()))
print ("This script is called {}".format(sys.argv[0]))
localtime = time.localtime(time.time())
print ("Local current time :{}".format(localtime))
now = time.asctime()
print ("The time now is {}".format(now))
LongDate = time.strftime("%A %B %d, %Y")
print ("Longformat {}".format(LongDate))
ISO = time.strftime("%Y-%m-%d %H:%M:%S : ")
print ("ISO {}".format(ISO))
if btKinterOK:
root = tk.Tk()
root.withdraw()
print ("Using the file open dialog please find the file to use")
strFilein = filedialog.askopenfilename(title = "Select file",filetypes = (("Text Files","*.txt"),("All Files","*.*")))
else:
strFilein = getInput("Please provide full path and filename for the CSV file to be imported: ")
iLoc = strFilein.rfind(".")
iNegLoc = iLoc * -1
print ("You selected: ", strFilein)
print ("Name {0} and ext {1}".format(strFilein[:iLoc],strFilein[iLoc:]))
statinfo = os.stat(strFilein)
print ("Stat Info: {}".format(statinfo))
print ("Last Accessed: {}".format(time.asctime(time.localtime(statinfo.st_atime))))
print ("Last Modified: {}".format(time.asctime(time.localtime(statinfo.st_mtime))))
print ("Created: {}".format(time.asctime(time.localtime(statinfo.st_ctime))))
print ("Name {0} and ext {1}".format(strFilein[:iLoc],strFilein[iLoc:]))
x = 0
strOutFile = "{0}-TS{1}{2}".format(strFilein[:iLoc],x,strFilein[iLoc:])
while os.path.isfile(strOutFile):
x += 1
strOutFile = "{0}-TS{1}{2}".format(strFilein[:iLoc],x,strFilein[iLoc:])
#end while file exists
print ("Out file:"+strOutFile)
objFileIn = open(strFilein,"r")
objFileOut = open(strOutFile,"w")
strLine = objFileIn.readline()
objFileOut.write (ISO + strLine)
while strLine:
ISO = time.strftime("%Y-%m-%d %H:%M:%S : ")
strLine = objFileIn.readline()
objFileOut.write (ISO + strLine)
#end while
objFileIn.close()
objFileOut.close()
now = time.asctime()
print ("Done at {} !!!".format(now))
#sys.exit(0)