How to change file date into the folder for yearly
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How to change file date into the folder for yearly.
A file sit into the folder need to date modify yearly itself.
any code for this to solve the issue not doing manually yearly.
Thanks
2 Commenti
Walter Roberson
il 17 Set 2022
Do I understand that you want to examine the file modification date of each file, and split the files into different folders by year of modification?
Risposte (1)
Walter Roberson
il 17 Set 2022
inputdir = 'appropriate directory name';
outputbasedir = 'parent folder for split directories';
dinfo = dir(inputdir);
dinfo([dinfo.isdir]) = []; %ignore subfolders and . and .. entries
for K = 1 : length(dinfo)
dv = datevec(dinfo(K).datenum);
yearstr = num2str(dv(1));
outfolder = fullfile(outputbasedir, yearstr);
if ~exist(outfolder, 'dir'); makedir(outfolder); end
sourcefile = fullfile(dinfo(K).folder, dinfo(K).name);
copyfile(sourcefile, outfolder);
end
If you want to move the files instead of copying them then change copyfile() to movefile()
If you want to process all immediate subdirectories of a parent directory then use
inputdir = 'appropriate directory name/*/*';
0 Commenti
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!