Reputation: 453
I've searched high and low but am struggling with the following code. In the for loop at the bottom, I need to iterate through the names in the first element of the mutlidimensional list. I'm very new to Python so please excuse my ignorance.
for file in files: # loop thru each recording
file_with_path = recording_fullpath + "/" + file #construct full file path
file_mtime = modification_date(file_with_path) # obtain file mod date
if file_mtime >= start_date and file_mtime <= end_date:
#print file + " is within the time range " + str(file_mtime)
archive_list[count].append (file_with_path)
archive_list[count].append (recording_subdir) # append filename with path to list
archive_list.append([])
count =+ 1
tarname = tar_path + "/" + client_id + "_" + dt.datetime.now().strftime("%Y%m%d_%H%M%S") + ".tar.gz"
print tarname
tar = tarfile.open (tarname, "w:gz")
for name in archive_list[][]:
print "Adding %s" % (name)
tar.add(name, arcname=client_id)
tar.close()
This code works when I just use a single element array but can't work out the syntax to include the second column.
Upvotes: 1
Views: 555
Reputation: 500377
tarname = tar_path + "/" + client_id + "_" + dt.datetime.now().strftime("%Y%m%d_%H%M%S") + ".tar.gz"
print tarname
tar = tarfile.open (tarname, "w:gz")
for name, dir in archive_list:
print "Adding %s" % (name)
tar.add(name, arcname=client_id)
tar.close()
This iterates over the list, unpacking every two-elements sublist into two variables, name
and dir
.
Upvotes: 1