필터 지우기
필터 지우기

Depositing processed files into a new directory

조회 수: 1 (최근 30일)
Gavin Brown
Gavin Brown 2015년 2월 13일
댓글: Image Analyst 2015년 2월 13일
I have developed a script to process .txt files of data from wind turbine noise into .out files.
I have created a directory at the start of the script with:
prompt1 = 'Name the destination folder:';
dlg_title1 = 'Create a destination folder';
num_lines = 1;
folder = inputdlg(prompt1,dlg_title1,num_lines);
m=cell2mat(folder);
str=sprintf('/%s',m);
mkdir('\\Biggar\noise\out. files',str);
But i'm unsure how to save the processed files into this directory. I'm using uigetfile to select the data, shown below:
%%Select data file using UI control
[filename,pathname] = uigetfile('*.txt', ...
'Select the TXT file to process', ...
'Multiselect','on');
if isequal(filename,0)
disp('User selected Cancel')
return;
end
% Fixup the one-file case using multi-select
if isstr(filename), filename={filename}; end
% Create name for output file and open for output
fname = lower([pathname,filename{n}]);
filenameOut = strrep(fname, 'txt', 'out');
[fid,msg] = fopen(filenameOut, 'w');
if fid==-1, error([msg ': ' filenameOut]),end % error w/ msg
fidtxt = fopen(fname, 'r');
if fidtxt==-1, error([msg ': ' fname]),end % error w/ msg
Finally, files are all closed at the end of the script after the processing with:
% Close 'Out' text file
fprintf(fid,'\r\nRun Date: %s',datestr(now));
fclose(fid);
Any ideas how to do this?
  댓글 수: 2
Gavin Brown
Gavin Brown 2015년 2월 13일
I've tried to use the movefile function but I'm not having much success.
dpb
dpb 2015년 2월 13일
편집: dpb 2015년 2월 13일
If this is a different subdirectory from which you're running and the input files are in, then you need to create the fully-qualified filename including that directory. If it is a directory below the current you can use relative addressing instead of absolute but still must refer to that specific directory.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2015년 2월 13일
You need to put the input files in the loop because you're letting the user select multiple files. You're not doing that now. If you don't want them to select multiple files, don't set multiselect to 'on'.
After you write stuff into fid, you need to close both the input and output files. Right now you're only closing the output file.
fclose(fidtxt);
fclose(fid);
  댓글 수: 2
Gavin Brown
Gavin Brown 2015년 2월 13일
Sorry I didn't make this clear. The script works for multiple files and the input files have been closed earlier in the script I just haven't included the whole script in the question. I only need to know how to move the output files into a specified folder. I could cut and paste in the whole script if you like?
Image Analyst
Image Analyst 2015년 2월 13일
You just make up the folder name first, before saving. Then save them directly to that folder. Why would you want to save them to the current folder, and then have the extra step of having to move them? It is inefficient.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by