How to be able to read file names with Swedish characters (ÅÄÖ) from a zipped file? Also how to unzip the files to a folder with the same name as the zipped folder?

2 vues (au cours des 30 derniers jours)
Hi
I have two quesions:
I am trying to unzip a folder which includes list text files with names containing Swedish characters like (Å,Ä,Ö, å, ä, ö). When using the function unzip, the Swedish characters with unzipped files are switched with � instead. For example when teh writing the following matlab code:
unzip('C:\Desktop\zipData\2019-06-10.zip','C:\Desktop\unzipData')
For example, the unzipped text file name in the folder C:\Desktop\unzipData would be Plant4_�A01_GT01 instead of Plant4_ÅA01_GT01.
I tried to change the encoding as below but it also did not work:
slCharacterEncoding('UTF-8')
Q1: is there a way fix the above mentioned issue?
Additionally, when using the function unzip('C:\Desktop\zipData\2019-06-10.zip','C:\Desktop\unzipData'), the function extract all the text files from 'C:\Desktop\zipData\2019-06-10.zip' and put them in 'C:\Desktop\unzipData'.
Since I have many zipped folders that contain text files, I would like each zipped folder to be unzipped into another folder with similar name.
For example, I have the following zipped folders on teh left and would like them to be unzipped into the folders on the right::
'C:\Desktop\zipData\2019-06-10.zip' unzip into 'C:\Desktop\unzipData\2019-06-10'
'C:\Desktop\zipData\2019-06-17.zip' unzip into 'C:\Desktop\unzipData\2019-06-17'
'C:\Desktop\zipData\2019-06-21.zip' unzip into 'C:\Desktop\unzipData\2019-06-21'
Q2: Is it possible to extract the zipped file into a folder with the same name as zipped folder?
Thanks for your help!

Réponses (1)

Guillaume
Guillaume le 1 Juil 2019
The documentation of unzip is a bit unclear on the effect of locale, all it has to say is "To extract a zip file that contains non-7-bit ASCII characters, extract the file on a machine that has the appropriate language/encoding settings". Matlab's documentation on locale setting is inadequate, but see this page. I'm not sure how slCharacterEncoding affects matlab locale, it seems to be a simulink function.
As for unzip into a specific folder with the same name as the zip file, simply pass that name as the output folder:
sourceroot = 'C:\Desktop\zipData';
destroot = 'C:\Desktop\UnzipData';
zipfiles = {'2019-06-10.zip', '2019-06-17.zip', '2019-06-21.zip'};
for fileidx = 1:numel(zipfiles)
[~, basename] = fileparts(zipfiles{fileidx});
unzip(fullfile(sourceroot, zipfiles{fileidx}), fullfile(destroot, basename));
end

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by