File Exchange

image thumbnail

slocDir

version 1.1.0.0 (2.44 KB) by David Roberts
Counts number source lines of code in a directory tree. (Requires sloc, FIle Exchange ID 3900)

28 Downloads

Updated 22 Jul 2009

View License

This function returns the line count for directory tree. If there are multiple functions in one file, subfunctions are not counted separately, but rather together. This function calls sloc.m to count lines of code on an individual file. Sloc can be obtained from the File Exchange on MATLAB Central.

The following statistics are calculated for a directory tree
- sum of lines of code from all mfiles in the directory tree
- sum of lines of code from all mfiles in parent directory
- sum of lines of code from all mfiles in subdirectories
- lines of code in each mfile in directory tree

The output of this function can either be to a text file or the MATLAB command prompt or both.

Comments and Ratings (8)

Seems to be doing the job. Must have been written by a non-MATLAB coder though. Teeming with unnecessary global variables and manually-coded functions that already exist in MATLAB (walkIn() could have been replaced by the MATLAB native genpath(), just to give an example).

dm b

amir soheil

this code calculate sum of no empty lines in ur project and calculate price of ur gui project by rate price per line

function costproject=castingprojecte1(mfilproject,ratperlin)
[fList0,~] = matlab.codetools.requiredFilesAndProducts(mfilproject);

fList=fList0';

for j=1:size(fList,1)
mf=(fList{j,1});
if strncmp(mf(1,end-1:(end)),'.m',2)==1
mftr(j,1)=true;
else
mftr(j,1)=false;
end

clear indx
fid = fopen(fList{j,1});

allText = textscan(fid,'%s','delimiter','\n');

netalltext=allText{1};

for i=1:size(netalltext,1)
if isempty(netalltext{i,1})==0
indx(i,1)=true;
else
indx(i,1)=false;
end
end

netalltext2=netalltext(indx,1);

numberOfLines{j,1} = length(netalltext2);
numberOfLines{j,2} = fList{j,1};
fclose(fid)
end
numberOfLines2=numberOfLines(mftr,:)
sumlinnoemp=sum(cell2mat(numberOfLines2(:,1)))
costproject=(ratperlin*sumlinnoemp)

Paul LaFonte

Paul LaFonte

Dimitrios

Updates

1.1.0.0

Note in summary to also download sloc from the file exchange.

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: sloc