how to update filename in a call to an external application ?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hans Jørgen Jensen
am 18 Aug. 2017
Kommentiert: Hans Jørgen Jensen
am 22 Aug. 2017
I just learned how to run a file with an external application. And that works. The application converts a datafile to CSV. The command looks like this:
!C:\Users\hjj019\Desktop\DLConverter.exe C:\Users\hjj019\Desktop\CA\TMWMU645.228
My next challenge, is to change the datafile file name so the routine converts one file after another. I worked out the code below, to find the path of the next file in my folder, but the command does not accept it as a valid file name. First I tried to use datastore, but since my datafiles have all sorts of random file extensions, I gave up on that, and tried a different way.
Here is what I have:
% Specify data location
dataloc = 'C:\Users\hjj019\Desktop\';
location1 = fullfile(dataloc,'CA');
[M,N] = size(dir(location1)) % Number of datalog files
for i = 1:M
files=dir(location1);
files1=files(M,1)
files2=files1.name
files3 = fullfile(location1,files2)
% Convert datalog files to CSV
_italic_
!C:\Users\hjj019\Desktop\DLConverter.exe files3
end
COMMAND WINDOW:
files1 = struct with fields:
name: 'TMWMU645.228'
folder: 'C:\Users\hjj019\Desktop\CA'
date: '13-jan-2015 09:36:14'
bytes: 25584
isdir: 0
datenum: 7.3598e+05
files2 = 'TMWMU645.228'
files3 = 'C:\Users\hjj019\Desktop\CA\TMWMU645.228'
Error: Could not open file files3
So my question is: How can I insert an updating filename in my file conversion command ?
3 Kommentare
Stephen23
am 18 Aug. 2017
@Hans Jørgen Jensen: it makes no sense to call dir inside the for loop: you only need to call dir once and loop over the structure that it returns. You will find very clear examples in the MATLAB help:
or on this forum:
and I would highly recommend that you follow those examples.
Akzeptierte Antwort
KL
am 21 Aug. 2017
Bearbeitet: KL
am 21 Aug. 2017
Hi Hans Jørgen Jensen ,
I've tried your code and yeah, I see your problem. I don't understand it but probably you could simply use system command to accomplish your task. Something like this,
% Specify data location
dataloc = 'C:\Users\hjj019\Desktop';
location1 = fullfile(dataloc,'CA');
[M,N] = size(dir(location1)) % Number of datalog files
files=dir(location1);
for iFile = 3:M
fileDetails=files(iFile,1)
fileName = fullfile(location1,fileDetails.name)
% Convert datalog files to CSV
system(['C:\Users\hjj019\Desktop\DLConverter.exe ' fileName])
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!