Depositing processed files into a new directory
2 次查看(过去 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 个评论
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
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 个评论
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 Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!