I have a working code that takes a list of file paths and reads them iteratively. For example:
class moveDcmNrrd4mJson_v3(object):
def __init__(self, jsonList, dataPath, dframe):
self.jsonList = jsonList #providing a list
self.dataPath = dataPath
self.dframe = dframe
def MoveFiles(self):
for jsonidx, jsonpath in enumerate(self.jsonList):
print("\n")
print(">>> Reading {} of {} json file: {}".format(jsonidx+1, len(self.jsonList), os.path.basename(jsonpath)))
That works when more than one file paths are in the list.
for example when:
['/media/banikr2/CAP_Exam_Data0/CAP Session Backups/wilist_all_MV_20180914-1053.json', '/media/banikr2/CAP_Exam_Data0/CAP Session Backups/wilist_all_MV_20180914-1418.json', '/media/banikr2/CAP_Exam_Data0/CAP Session Backups/wilist_all_MV_20180914-1452.json', '/media/banikr2/CAP_Exam_Data0/CAP Session Backups/wilist_all_MV_20180914-1517.json', '/media/banikr2/CAP_Exam_Data0/CAP Session Backups/wilist_all_MV_20180914-1705.json']
I want to make it work when only single filepath. For example when I call jsonList[-1]
with the same enumerate
loop. Now the loop just iterate over the path ASCII characters.
Calling the code as:
A = moveDcmNrrd4mJson_v3(jsonList[2], capDir, df) # only one filepath
A.MoveFiles()
I have seen some suggestions here in this post however not exactly clear to me.