MATLAB: How to delete files ending with odd number delete filesdelete oddextract filenameodd number Hi, I would like to delete each files having its filename ending by an odd number. Example: file0 file1 file2 file3 file4 After: file0 file2 file4 Thank you for your help 🙂 Best Answer You could looop through all the files and delete ones that have an odd number using regexp, regular expression searchfiles = dir('*'); % find all files in current directoryfor i=1:length(files), fileno = str2double(cell2mat(regexp(files(i).name, '[0-9]{1,}', 'match'))); if mod(fileno, 2) == 1, % check if fileno modulo 2 == 1 delete(files(i).name); endend Related SolutionsMATLAB: Avoid reading files in alphabetical order Matlab dir See this..http://www.mathworks.com/matlabcentral/fileexchange/10959 MATLAB: Changing the names of text files in a directory Copy all your files to a folder named '\test' under current folder, run the following code.Folder=fullfile(pwd,'test');Files=dir(Folder);for k=1:length(Files) [PathStr,FileName,FileExt]=fileparts(Files(k).name); if length(FileExt)==4 % Exclude folder . and folder .. movefile(fullfile(Folder,Files(k).name),... fullfile(Folder,['naic',FileExt(2:end),'.txt'])); endend Related QuestionDir() function not workingHow to input file but file depend to extensionRename images using counterHow to extract the names of all the files with an specific extension content in different directories and omit the name if is repeatedRenaming a lot of filesRenaming multiple subfolders within folderProblem with sorting a structure
Best Answer