-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiteratefolders.py
39 lines (37 loc) · 1.47 KB
/
iteratefolders.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
#DON"T RUN THIS CODE AGAIN you've already moved all the correct zipfiles to eventfiles folder
import os
import pathlib
import timeit
import glob
import gzip
import shutil
path = r"w3browse-49652"
def a():
list_subfolders_with_paths = [f.path for f in os.scandir(path) if f.is_dir()]
#print(len(list_subfolders_with_paths))
i=0
j=len(list_subfolders_with_paths)
while(i<j):
path2=os.path.join(list_subfolders_with_paths[i]+'/xrt/event') #joining a Python variable with an extension to obtain a path name
list_swift_files_paths = [f.path for f in os.scandir(path2) if f.is_file()]
#print(path2)
#print(list_swift_files)
k=0
l=len(list_swift_files_paths)
while(k<l):
if(list_swift_files_paths[k].find('pcw3po_cl.evt.gz') != -1):
myfile = list_swift_files_paths[k][37:]
#gzip.GzipFile(list_swift_files_paths[k], mode='r')
with gzip.open(list_swift_files_paths[k], 'rb') as f_in:
with open('eventfiles/'+myfile, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
'''
file2 = open(list_swift_files_paths[k], 'r')
file2.extractall('./eventfiles')
with ZipFile(list_swift_files_paths[k]) as myzip:
with myzip.open(myfile) as myfile2:
print(myfile2.read())
'''
k=k+1
i=i+1
a()