How to change file date into the folder for yearly
4 views (last 30 days)
Show older comments
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
Answers (1)
Walter Roberson
on 17 Sep 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 Comments
See Also
Categories
Find more on File Operations 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!