I think what I’m trying to do is very basic but I’m a rank beginner and I’m stuck. I’m using Python 2.4.1 on WindowsNT. I’ve installed UnxUtils, which includes the tar commands for Windows.
Immediate objective:
I have a text file containing a list of tar files, one filename per line. For now I’m just trying to loop through my text file and untar each file in the list.
Background/big picture:
Ultimately I’d like to
• Loop through the list and untar each tar file (~1700 files total),
• import some of the un-tarred components of the original tar file into an image processing program (ERDAS Imagine),
• zip the output from Imagine, and
• delete the unneeded files from the original tar.
So far, I’m able to loop through the list and print filenames. Also, the tar command is working from the command line (and batch file) but I’m missing something when I try to integrate the tar command onto python.
Here’s what I’ve got so far:
#####Loop through and print each line (works fine):
#####Trying to add tar component:
Thanks in advance...
Immediate objective:
I have a text file containing a list of tar files, one filename per line. For now I’m just trying to loop through my text file and untar each file in the list.
Background/big picture:
Ultimately I’d like to
• Loop through the list and untar each tar file (~1700 files total),
• import some of the un-tarred components of the original tar file into an image processing program (ERDAS Imagine),
• zip the output from Imagine, and
• delete the unneeded files from the original tar.
So far, I’m able to loop through the list and print filenames. Also, the tar command is working from the command line (and batch file) but I’m missing something when I try to integrate the tar command onto python.
Here’s what I’ve got so far:
#####Loop through and print each line (works fine):
Code:
import fileinput path = r"C:\WorkSpace\LTC\MRLC_test\NZT\tmp" inFile = open(path + "\\tarList7.txt", 'r') for line in inFile: print line inFile.close() print "Done!"
Code:
import fileinput import tarfile path = r"C:\WorkSpace\LTC\MRLC_test\NZT\tmp" inFile = open(path + "\\tarList2.txt", "r") line = inFile.readline() tar = tarfile.open(line) for line in inFile: print line tar.extractall() tar.close() inFile.close()
Comment