MATLAB Answers

how to detect folder address

1 view (last 30 days)
A
A on 6 Dec 2012
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 Comments

Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 6 Dec 2012
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 Comments

Sign in to comment.

More Answers (1)

Jonathan Sullivan
Jonathan Sullivan on 6 Dec 2012
Edited: Jonathan Sullivan on 6 Dec 2012
You might consider mfilename
pathh = fileparts(mfilename('fullpath'))
help mfilename
doc mfilename

  0 Comments

Sign in to comment.

Tags