how to detect folder address
古いコメントを表示
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
採用された回答
その他の回答 (1 件)
Jonathan Sullivan
2012 年 12 月 6 日
編集済み: Jonathan Sullivan
2012 年 12 月 6 日
You might consider mfilename
pathh = fileparts(mfilename('fullpath'))
help mfilename
doc mfilename
カテゴリ
ヘルプ センター および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!