how to detect folder address
조회 수: 2 (최근 30일)
이전 댓글 표시
The following code performs an operation on all files present in a folder specified by "pathh". I need to be able to copy the compiled executable version of this code into any folder and have the opearion done on all files in that folder. In other words, have it detect it's own folder location and use it for "pathh"
clear all;close all;
pathh='C:\...\folder1\';
list=ls(pathh);m=size(list);
addpath(pathh);
for i=3:m(1)
file=list(i,:);
fid_v=fopen(strtrim(file),'r')
fid_o=fopen(strcat(pathh,file,'_out.txt'),'w')
while ~feof(fid_v)
line = fgetl(fid_v);
fprintf(fid_o,line);
fprintf(fid_o,'\r\n');
line = fgetl(fid_v);
end
fclose(fid_v);
fclose(fid_o);
end
댓글 수: 0
채택된 답변
Sean de Wolski
2012년 12월 6일
doc dir
Is probably the individual most important since it gives you everything the folder. These may help as well:
doc fullfile
doc pwd
댓글 수: 0
추가 답변 (1개)
Jonathan Sullivan
2012년 12월 6일
편집: Jonathan Sullivan
2012년 12월 6일
You might consider mfilename
pathh = fileparts(mfilename('fullpath'))
help mfilename
doc mfilename
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!