How to change file date into the folder for yearly

5 visualizzazioni (ultimi 30 giorni)
Nav
Nav il 17 Set 2022
Risposto: Walter Roberson il 17 Set 2022
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
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?
Nav
Nav il 17 Set 2022
@Walter Roberson yes correct,
Even though same file must be its date modified can stay into same folder and overwrite with older file.

Accedi per commentare.

Risposte (1)

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

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by