-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_files.py
executable file
·50 lines (44 loc) · 1.65 KB
/
list_files.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
#!/usr/bin/env python
from helpers import get_instrument, write, query, ieee_488_2_block_data
import os, re
split_regex = ''',(?=(?:[^'"]|'[^']*'|"[^"]*")*$)'''
def strip_result(result):
match = re.match('"(.*),,\d*"', result)
return match.group(1)
def list_files(device=None, backend=None, paths=None):
inst = get_instrument(device, backend=backend)
if not paths:
paths = (
'/INT',
'/INT/SETTINGS',
'/INT/DATA',
'/INT/REFERENCE',
'/INT/FORMULARY',
'/INT/BUSTABLE',
'/INT/SEARCH',
'/INT/STATISTICS',
'/INT/DEMO',
'/INT/LOG',
'/INT/SETTINGS',
'/USB_FRONT' )
inst.query('MMEMory:DRIVes?') # -> "/INT","/USB_FRONT"
for path in paths:
inst.write('MMEMory:MSIS "/' + path.split('/')[1] + '"') # change to this drive
inst.write('MMEMory:CDIRectory "' + path + '"')
# --- sub folders
sub_folders = inst.query('MMEMory:DCATalog? "' + path + '/*"').strip()
sub_folders = re.split(split_regex, sub_folders)
sub_folders = [strip_result(s) for s in sub_folders]
if sub_folders == ['.', '..']: sub_folders = []
for sub_folder in sub_folders:
#print(os.path.join(path, sub_folder) + '/')
pass
# --- files
files = inst.query('MMEMory:CATalog? "' + path + '/*.*",WTIMe')
files = re.split(split_regex, files)
files = files[2:]
files = [strip_result(f) for f in files]
for f in files:
print(os.path.join(path, f))
if __name__ == "__main__":
list_files()