Sort files in folder based on type

3 ビュー (過去 30 日間)
Avni
Avni 2022 年 8 月 1 日
回答済み: Stephen23 2022 年 8 月 1 日
I have a folder that has 502 files - 251 .txt files and 251 .ecf files and I want to sort all the files into 2 folders so they're separated by type (so for example I'd have folders called "ecf files" and "text files").
I wrote a code to sort the files based on name so is it possible to modify this to sort by type? Thank you!
no_folders = input('How many folders would you like to create? ');
no_runs = input('How many runs? ');
names = {};
for i=1:no_folders
name_temp = input(sprintf('Enter name of folder %i ',i),"s");
names{i} = name_temp;
mkdir(names{i});
end
%stores .txt output files into files using dir()
files = dir('*.txt');
file_names = {files.name};
for k=1:no_folders
for j=1:no_runs
if contains(file_names{j},names{k})==1
movefile(file_names{j}, names{k});
end
end
end

回答 (1 件)

Stephen23
Stephen23 2022 年 8 月 1 日
mkdir('ecfFiles')
mkdir('txtFiles')
movefile('*.ecf','ecfFiles')
movefile('*.txt','txtFiles')

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by