Depositing processed files into a new directory

1 次查看(过去 30 天)
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