How to change file date into the folder for yearly

4 views (last 30 days)
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.
Nav on 17 Sep 2022
@Walter Roberson yes correct,
Even though same file must be its date modified can stay into same folder and overwrite with older file.

Sign in to comment.

Answers (1)

Walter Roberson
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);
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/*/*';


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!

Translated by