-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddRunNumb-Galaxy-Array.py
77 lines (51 loc) · 1.48 KB
/
AddRunNumb-Galaxy-Array.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
74
#!/usr/bin/env python
# coding: utf-8
import os
import sys
import optparse
import datetime
import subprocess
from glob import glob
from collections import defaultdict
from collections import OrderedDict
from array import array
import time
import re
import numpy as np
import copy
import shutil
from os import path
'''
# folder path
dir_path = '/data/cmsdaq/DimensionBench/TEST/Arrays/ArrayData'
# list to store files
res = []
# Iterate directory
for path in os.listdir(dir_path):
# check if current path is a file
if os.path.isfile(os.path.join(dir_path, path)):
res.append(path)
print(res)
'''
runNumberFileName='RunNumberGalaxyArray.txt'
print(runNumberFileName)
dir = '/data/cmsdaq/DimensionBench/Arrays/ArrayData/'
ext = ('.TXT')
for file in os.listdir(dir):
if file.endswith(ext):
old_filepath = os.path.join(dir, file)
currentRun = 0
outputFileName = runNumberFileName
file_runs = open(outputFileName, 'a+')
lastRun = subprocess.check_output(['tail', '-1', outputFileName])
lastRun = lastRun.rstrip(b'\n')
if not lastRun:
currentRun = 1
else:
currentRun = int(lastRun) + 1
file_runs.write(str(currentRun)+'\n')
newlabel = 'Run'+str(currentRun).zfill(6)+str('_')
new_name = newlabel + file
new_filepath = os.path.join(dir, new_name)
os.rename(old_filepath, new_filepath)
file_runs.close()