MATLAB如何获取文件夹的大小

MATLAB如何获取文件夹的大小,第1张

就是里面的文件大小加起来吧,

用dir,

结果里有文件大小。

别忘了算子文件夹什么的

windows看文件夹大小也只能现算的

function

[

sum

]

=

FolderSize(

folderName

)

%FOLDERSIZE

Summary

of

this

function

goes

here

%

Detailed

explanation

goes

here

sum

=

0;

lst

=

dir(folderName);

for

index

=

1:length(lst)

if

strcmp(lst(index)name,

'')

||

strcmp(lst(index)name,

'')

continue;

end

if

lst(index)isdir

sum

=

sum

+

FolderSize([folderName

'\'

lst(index)name]);

else

sum

=

sum

+

lst(index)bytes;

end

end

end

使用Matlab搜索特定后缀名的文件,把该文件所在的文件夹路径提取出来方法如下:

加入文件夹搜索路径 -- addpath (Add folders to search path)

ddpath('folderName1','folderName2','folderName3' )

addpath('folderName1','folderName2','folderName3' flag)

addpath folderName1 folderName2 folderName3 -flag)

previous_path = addpath()

这里的flag为

'-begin' :Add specified folders to the top of the search path

'-end' :Add specified folders to the bottom of the search path

'-frozen' :Disables change detection for folders you add to the path, which conserves Windows change notification resources (Windows only) Typehelp changenotification in the Command Window for more information

例子:

Add c:/matlab/myfiles to the top of the search path:addpath('c:/matlab/myfiles')Add c:/matlab/myfiles to the end of the search path:addpath c:/matlab/myfiles -endAdd myfiles and its subfolders to the search path:addpath(genpath('c:/matlab/myfiles'))

On Windows, Add myfiles to the top of the search path, disable folder change notification, and display the search path before adding myfiles:previous = addpath('c:/matlab/myfiles', '-frozen')

去除文件夹搜索路径 rmpath (Remove folders from search path)

rmpath('folderName') removes the specified folder from the search path Use the full path forfolderName

rmpath folderName is the command form of the syntax

如果想把该目录下的所有子目录都添加到路径中去,也不用把所有的子目录逐一addpath,用genpath函数:

Use genpath in conjunction with addpath to add a folder and its subfolders to the search path Add myfiles and its subfolders to the search path:

addpath(genpath('c:/matlab/myfiles')

这样:

imgPath = 'E:/imageData/';        % 图像库路径

imgDir  = dir([imgPath 'jpg']); % 遍历所有jpg格式文件

for i = 1:length(imgDir)          % 遍历结构体就可以一一处理了

img = imread([imgPath imgDir(i)name]); %读取每张

end

扩展资料:

注意事项

imgDir返回的是一个结构体,包含每个name(名称),date(日期),bytes(字节数),isdir(是否为文件夹/目录),datenum(修改日期,连续日期号码)。一般我们仅需使用名称就可以完成遍历的工作

需要先遍历所有子文件夹,然后依次再遍历每个子文件夹下的。程序如下:

imgDataPath = 'E:/imageData/';

imgDataDir  = dir(imgDataPath);             % 遍历所有文件

for i = 1:length(imgDataDir)

if(isequal(imgDataDir(i)name,'')|| % 去除系统自带的两个隐文件夹

isequal(imgDataDir(i)name,'')||

~imgDataDir(i)isdir)                % 去除遍历中不是文件夹的

continue;

end

imgDir = dir([imgDataPath imgDataDir(i)name '/jpg']);

for j =1:length(imgDir)                 % 遍历所有

img = imread([imgDataPath imgDataDir(i)name '/' imgDir(j)name]);

end

end

1 图像按编号命名:1jpg, 2jpg,,njpg

2 循环读图

I=cell(1,n);

for i=1:n

imageName=strcat(num2str(i),'jpg');

I{i} = imread(imageName);

end

3 处理图像

-----------------------

如果图像很多,那么最好这样,第二步和第三步合并

for i=1:n

imageName=strcat(num2str(i),'jpg');

I = imread(imageName);

处理当前图像

以上就是关于MATLAB如何获取文件夹的大小全部的内容,包括:MATLAB如何获取文件夹的大小、如何使用Matlab搜索特定后缀名的文件,把该文件所在的文件夹路径提取出来、怎样用matlab读取一个文件夹下的多个子文件夹中的多个jpg图片,急用啊~~~等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9432772.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存