How can I store the compressed file into a different folder with the same structure as the original?

1 回表示 (過去 30 日間)
How can I compress each file and store it into a new folder with the same structure as the orginal?
If any error occurs during compression, I'm using 'try catch' to skip the file and write the error to temp.Compression_Error
The code I am using is below:
root = 'C:\users\19108\Documents'
dirlist = dir(fullfile(root, '**\*.*'));
filelist = dir(~[dirlist.isdir]);
names = {filelist.names};
folder = {filelist.folder};
Filepath = strcat(folder,"\",names)';
numfiles = length(Filepath);
temp = table;
temp.Filepath = Filepath
temp.Compressoin_Error = cell(numfiles,1)
mkdir C:\users\19108\Documents newfolder
for i = 1:numfiles
try
compressed = gzip(Filepath{i}, 'C:\users\19108\Documents\newfolder');
catch matlabError
temp.Compression_Error{i} = {matlabError};
end
end

回答 (1 件)

Image Analyst
Image Analyst 2023 年 7 月 17 日
See the FAQ:
If you still can't figure out how to adapt the FAQ code, then write back, but it should be pretty straightforward.
  6 件のコメント
Rookie Programmer
Rookie Programmer 2023 年 7 月 18 日
After compressing the files, I'm not getting the expected structure of the output.
Image Analyst
Image Analyst 2023 年 7 月 19 日
OK, I read your reply. Good luck with it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by