Unzipping a .tgz file

Hi all, I have encountered difficulty trying to use the untar function to extract a .tgz file that contains many text files within it. I get an error for every single text file saying
Warning: Permission denied to create file "C:<redacted for privacy>".
> In extractArchive>extractArchiveEntry (line 109)
In extractArchive (line 52)
In untar (line 79)
Here's what I've tried to troubleshoot the problem:
  • I am able to use 7-zip to unzip the same .tgz succesfully, so I know it is not a problem with the file itself
  • When the same files are contained in a .tar.gz folder, MATLAB works, so I don't think it's a permissions issue with the directory (for reference, the directory is just a random folder on my Desktop, nothing fancy)
  • There are no existing files with that name that are being overwritten.
The untar documentation says that the function works for .tgz files, but that doesn't seem to be the case in my situation? Thanks in advance for any advice.

6 Comments

Can you share your file, so that I can reproduce the problem from my end? Also, Is the file already opened outside MATLAB, while you are using 'untar()'?
MJ
MJ on 30 Dec 2020
Hi Abhishek, thank you for your reply. Unfortunately I'm not able to share the contents of the file. As for your other question, the file is not opened outside of MATLAB when I am trying to untar().
I just tried out untar on a text file that I compressed into .tgz myself and didn't run into any issues, so perhaps it is a problem with the specific file that I am trying to unzip?
I realize that without sharing the file, it will be difficult to debug. However, if you have any suggestions, I'd appreciate it!
Can you share fileattrib() of the directory ?
Hi Walter, the fileattrib() is as follows:
Name: '<redacted>'
archive: 0
system: 0
hidden: 0
directory: 1
UserRead: 1
UserWrite: 0
UserExecute: 1
GroupRead: NaN
GroupWrite: NaN
GroupExecute: NaN
OtherRead: NaN
OtherWrite: NaN
OtherExecute: NaN
I realize it's odd that UserWrite is 0, but untar works on my trial file in the same folder.
MJ
MJ on 30 Dec 2020
I think the problem may be due to a colon character in the compressed file name, which is not an accepted character for Windows. I noticed that untar doesn't have an option to rename the files as they are extracted, would the appropriate thing to do in this situation be to modify the untar.m/extractArchive.m source code to include such a clause? Thanks for your feedback!
Colon character in the file name would potentially be a problem -- but notice that UserWrite is 0 so you do not have permission to write in the directory.

Sign in to comment.

 Accepted Answer

MJ
MJ on 30 Dec 2020

0 votes

Hi all, thanks for the feedback which helped me debug the situation. Rather than modifying untar (in a separate file of course), I've decided to go with this code provided by Wouter to unzip with 7zip using system command. 7-zip appears to take care of the filename problem itself.

More Answers (0)

Categories

Asked:

MJ
on 17 Dec 2020

Commented:

on 30 Dec 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!