-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.py
More file actions
59 lines (51 loc) · 1.55 KB
/
create.py
File metadata and controls
59 lines (51 loc) · 1.55 KB
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
# !/user/bin/env python
# -*- coding:utf-8 -*-
import os
import time
def getnowdatatime(flag=0):
'''
flag = 0 eg:2018-04-11 10:04:55
flag = 1 eg:2018-04-11
flag = 2 eg:10:04:55
flag = 3 eg:20180411100455
'''
now = time.localtime(time.time())
if flag == 0:
return time.strftime('%Y-%m-%d %H:%M:%S', now)
if flag == 1:
return time.strftime('%Y-%m-%d', now)
if flag == 2:
return time.strftime('%H:%M:%S', now)
if flag == 3:
return time.strftime('%Y%m%d%H%M%S', now)
# generate a file with predefined size
def generateTXTFile(filepath, fileSize):
if fileSize >= 200:
print('creating a file, please waiting... ...')
filename = getnowdatatime(3) + '_' + str(fileSize) + 'MB.txt'
print(f'filepath: {filepath}; filename:{filename}')
f = open(filepath + filename, 'w')
starttime = getnowdatatime()
startclock = time.time()
for i in range(fileSize):
if i >= 100:
if i % 100 == 0:
print(f'generated {i//100 * 100}MB data.')
for j in range(1000):
try:
f.write('01' * 500)
except KeyboardInterrupt:
print('\nAbnormal Interruption!:KeyboardInterrupt')
f.close()
exit(-1)
f.close()
print(f'generated file, size:{fileSize}MB.\n', os.path.getsize(filepath + filename))
print(f'DetailInfo:')
print(f'path: {filepath + filename}')
print(f'start:{starttime}')
print(f'end:{getnowdatatime()}')
print(f'time cost:{(time.time() - startclock):<.3}sec.')
return filepath + filename
if __name__ == '__main__':
x = generateTXTFile('./files/', 1)
print(x)