I want to open a folder containing x zipfiles.
I have this code:
JavaScript
x
7
1
parser = argparse.ArgumentParser(description='Test')
2
parser.add_argument("foldername", help="Foldername of log files archive to parse")
3
args = parser.parse_args()
4
with open(args.foldername) as files:
5
filename = args.filename
6
print(filename)
7
But I get error code: PermissionError: [Errno 13] Permission denied: ‘Test’
I would like the zipfiles in the folder to be listed in an array when I run the code.
Advertisement
Answer
I’m not sure why you’re getting a permission error, but using open
on a directory won’t do what you want. The documentation for Python’s open
requires that its input is a string to a file, not a directory.
If you want the files in a directory given the name of the directory as a string, refer to How can I iterate over files in a given directory?