cleanDir

Below is a demonstration of the features of the cleanDir function

Contents

clear; close all; clc;

Syntax

cleanDir(pathName,extCell);

Description

This function can clean a folder by removing either all files in a folder or all files with the extensions specified in the cell array extCell.

E.g. if one is interested in removing all .txt and .xml files from the folder specified by pathName on could use: pathName='D:\MATLAB\GIBBON' extCell={'txt','xml'}; %Extensions of files to delete cleanDir(pathName,extCell);

Examples

Create an example folder containing files with 3 different extensions, i.e. txt, csv and doc.

% Create temporary example folder
defaultFolder = fileparts(fileparts(mfilename('fullpath')));
pathName=fullfile(defaultFolder,'data','temp','cleanCheck');
mkdir(pathName)

% Create files
n=3; %Number of files for each type
for q=1:1:n %Create n files
    fileID=fopen(fullfile(pathName,['temp',num2str(q),'.txt']),'w');
    fprintf(fileID,'%d\n',pi);
    fclose(fileID);
end

for q=1:1:n %Create n files
    fileID=fopen(fullfile(pathName,['temp',num2str(q),'.csv']),'w');
    fprintf(fileID,'%d\n',pi);
    fclose(fileID);
end

for q=1:1:n %Create n files
    fileID=fopen(fullfile(pathName,['temp',num2str(q),'.xml']),'w');
    fprintf(fileID,'%d\n',pi);
    fclose(fileID);
end

Show current folder content

disp('Old folder content:')
ls(pathName)
Old folder content:
temp1.csv  temp1.xml  temp2.txt  temp3.csv  temp3.xml
temp1.txt  temp2.csv  temp2.xml  temp3.txt

Clean up directory by removing all files whose extensions are a member of the extension set provided.

extCell={'csv','txt'}; %File extensions for files to remove
cleanDir(pathName,extCell)

Show current folder content

disp('New folder content:')
ls(pathName)
New folder content:
temp1.xml  temp2.xml  temp3.xml

remove the temporary folder created for this example

rmdir(pathName,'s')

GIBBON www.gibboncode.org

Kevin Mattheus Moerman, [email protected]

GIBBON footer text

License: https://github.com/gibbonCode/GIBBON/blob/master/LICENSE

GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for image segmentation, image-based modeling, meshing, and finite element analysis.

Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.