Depositing processed files into a new directory
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
dpb
el 13 de Feb. de 2015
Editada: dpb
el 13 de Feb. de 2015
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.
Respuestas (1)
Image Analyst
el 13 de Feb. de 2015
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 comentarios
Image Analyst
el 13 de Feb. de 2015
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.
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!