Borrar filtros
Borrar filtros

Depositing processed files into a new directory

2 visualizaciones (últimos 30 días)
Gavin Brown
Gavin Brown el 13 de Feb. de 2015
Comentada: Image Analyst el 13 de Feb. de 2015
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
Gavin Brown
Gavin Brown el 13 de Feb. de 2015
I've tried to use the movefile function but I'm not having much success.
dpb
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.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
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
Gavin Brown
Gavin Brown el 13 de Feb. de 2015
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 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.

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by