天天看點

matlab 複制檔案夾,matlab檔案/檔案夾操作

筆記:

路徑操作:

定義路徑:

f = fullfile("c","download");

pwd %傳回目前路徑

cd('c:/toolbox/matlab/demos') %切換目前工作目錄到demos

cd .. %切換目前工作目錄到matlab

檔案夾操作:

boolean isfolder(f)

boolean isempty(f)

files=dir(f)

files(3).name

folder

date

bytes

isdir

datenum

length(files)

strncmp(files(ii).name, '.', 1)

%因為files得到的前幾個元素是".",是以比較兩個字元串前1個字母是否完全比對

copyfile(oldpath, newpath);

檔案操作:

copyfile(oldpath, newpath);

io

fid = fopen('D:\360Downloads\11\result.txt');

tline=fgetl(fid); %從檔案中讀取行,删除檔案換行符,傳回字元串

matlab讀取文檔後截取特定字元

fid = fopen('D:\360Downloads\11\result.txt');

%打開

tline=fgetl(fid); %從檔案中讀取行,删除檔案換行符,傳回字元串

%擷取第一行的行數列數

[row col] = size(tline);

% 擷取‘print’所在的列數

print = findstr(tline,'print');

vein = findstr(tline,'vein') ;

user_id = findstr(tline,'user_id:44 ');

p_value = str2num(tline(1,print+6:vein-2));

v_value = str2num(tline(1,vein+5:user_id-2));

複制檔案夾下所有jpg檔案

f=fullfile('1')

move(f)

function move(f)

%輸入路徑,對檔案夾下的所有檔案執行

if exist(f)~=0

files = dir(f)

% move_file(f)

count =length(files);

if count<3

return;

end

for i = 3:count

subf = fullfile('1',files(i).name)

if isfolder(subf) && ~isempty(subf)

move(subf)

else

move_file(f)

end

end

end

end

function move_file(image0Folder)

% 複制檔案夾下所有zip檔案,不包括子檔案夾

image0File=dir(fullfile(image0Folder,'*.jpg'));

count=length(image0File);

% 周遊複制

for i = 1:count

name = image0File(i).name;

image0Path = [image0Folder,'\',name];

copyfile(image0Path,'D:\codestudy\fun_matlab_code\move_file\2'); %%複制前位址,複制後位址

end

end

疑問:

怎樣複制檔案并且重命名?

txt檔案打開亂碼,怎麼更改編碼方式?

matlab 複制檔案夾,matlab檔案/檔案夾操作
matlab 複制檔案夾,matlab檔案/檔案夾操作

longzu233

釋出了9 篇原創文章 · 獲贊 0 · 通路量 107

私信

關注

标簽:files,檔案,tline,檔案夾,matlab,fid,print

來源: https://blog.csdn.net/longzu233/article/details/104437632