To delete gunziped file
1 view (last 30 days)
Show older comments
I am using gunzip to get the unzipped file from .gz file. I need that I get data from the unzipped file and don't get a copy of unzipped file. This is because unzipped file take a lot of space and I have 1000s of such file. i.e. I want to delete the unzipped file as soon as I get required data from it. OR Is there any way to get only required data from .gz file.
Thanks in advance Pooja
2 Comments
Stephen23
on 2 Sep 2014
But it is not clear what you are actually trying to do. Are you doing this in a loop? In what form is your list of filenames? Do you generate the filenames on the fly? Where are the files located?
We need to know a bit more about what you are doing, in order to have an idea of how to solve your problem.
Please read this advice on how to write a question that will make it easier for people to help you, then edit your question to provide a minimum working example of your code.
Accepted Answer
Guillaume
on 2 Sep 2014
You need to close the file before deleting it. Write
fclose(file);
before
delete(file);
2 Comments
Stephen23
on 2 Sep 2014
Edited: Stephen23
on 2 Sep 2014
It is a good idea to keep fopen and fclose calls very close to each other, to avoid eaxctly this kind of problem: basically as soon as you write fopen you should write the following fclose too. And keep only the bare minimum amount of code in between, usually reading/writing whatever data is required.
Note that fclose('all') could cause problems if this function is called from another function that has and requires an open file...
More Answers (0)
See Also
Categories
Find more on Problem-Based Optimization Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!