MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [求助]Matlab清空指定文件夹 (https://www.labfans.com/bbs/showthread.php?t=6869)

wwb624 2009-03-16 15:58

[求助]Matlab清空指定文件夹
 
Matlab清空指定文件夹

如何用matlab删除指定文件夹下的所有文本文件??

applef 2009-03-17 12:43

回复: [求助]Matlab清空指定文件夹
 
把这个改改用吧。

%% 指定输入目录,搜索原始txt文件
INP = uigetdir('C:\','请指定删除txt文件的目录');
if INP ~= 0 % 判断是否指定了输入目录
structFiles = dir(INP);
nMaxFileNum = length(structFiles);
sTxtFiles = cell(1,nMaxFileNum);
iTxtFind = 0;
for idFile = 1:length(structFiles) % 判断文件
% 寻找Txt文件
if ~structFiles(idFile).isdir
sName = structFiles(idFile).name;
if length(sName)>4 % .Txt文件至少有四个字
sNameType = sName(end-3:end);
sNameFirst= sName(1:end-4);
if(strcmp(sNameType,'.Txt')||strcmp(sNameType,'.txt'))
% this is a txt file
iTxtFind = iTxtFind + 1;
sTxtFiles{iTxtFind} = sNameFirst;
end
end
end
end % 判断文件结束
sTxtFiles = sTxtFiles(1:iTxtFind);
sFindFile = strcat('共发现Txt文件个数: ',int2str(iTxtFind));
disp(sFindFile);
end


所有时间均为北京时间。现在的时间是 11:22

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.