processing filenames returned by glob

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

processing filenames returned by glob

Ether Jones-2
Hello.

I used glob to return a cell array of filenames.

Now I want Octave to load and process each of those filenames, one at a time, and generate a separate output file for each input file.

Can someone please point me in the right direction?

Or is there a better way to do this?

Thank you.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: processing filenames returned by glob

NJank
On Wed, May 3, 2017 at 12:25 PM, Ether Jones <[hidden email]> wrote:

>
> Hello.
>
> I used glob to return a cell array of filenames.
>
> Now I want Octave to load and process each of those filenames, one at a time, and generate a separate output file for each input file.
>
> Can someone please point me in the right direction?
>
> Or is there a better way to do this?
>

ok, so you have a list of filenames. Are these m-file scripts? data files you want to load and process in some way? .mat files that will bring in a bunch of variables when loaded? ...?

your filenames are strings, so there are a bunch of ways you could use a for loop appending that filename string to some other command like load, fopen, dlmread, etc.  See:

https://www.gnu.org/software/octave/doc/v4.2.1/Simple-File-I_002fO.html

You can do a similar thing for file output once you have done whatever needs to be done. In you're loop you'll want to save data, where the save-as filename will somehow reflect the unique aspect of what was done, be it just appending the input filename, or something.

More specifics might produce more specific advice :)

Nick J.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: processing filenames returned by glob

Ether Jones-2
In reply to this post by Ether Jones-2


On Wed, May 3, 2017 at 12:39 PM, Nicholas Jankowski <[hidden email]> wrote:
On Wed, May 3, 2017 at 12:25 PM, Ether Jones <[hidden email]> wrote:

>
> Hello.
>
> I used glob to return a cell array of filenames.
>
> Now I want Octave to load and process each of those filenames, one at a time, and generate a separate output file for each input file.
>
> Can someone please point me in the right direction?
>
> Or is there a better way to do this?
>

ok, so you have a list of filenames. Are these m-file scripts? data files you want to load and process in some way? .mat files that will bring in a bunch of variables when loaded? ...?

your filenames are strings, so there are a bunch of ways you could use a for loop appending that filename string to some other command like load, fopen, dlmread, etc.  See:

https://www.gnu.org/software/octave/doc/v4.2.1/Simple-File-I_002fO.html

You can do a similar thing for file output once you have done whatever needs to be done. In you're loop you'll want to save data, where the save-as filename will somehow reflect the unique aspect of what was done, be it just appending the input filename, or something.

More specifics might produce more specific advice :)

Nick J.

​The filenames I fetched into a cell array using glob are data files in CSV format.  I want to run an Octave function separately on each of those data files (to process the data)​
 
​ ​and produce a separate output report file for each data file.

I know how to load a CSV file and process it with Octave.  What I don't know (and am asking for help - ideally an example code snippet) is how to extract the filenames from the cell array that glob created so that I can load and process them one at a time.

Thank you.


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: processing filenames returned by glob

Dmitri A. Sergatskov
On Wed, May 3, 2017 at 12:21 PM, Ether Jones <[hidden email]> wrote:


On Wed, May 3, 2017 at 12:39 PM, Nicholas Jankowski <[hidden email]> wrote:
On Wed, May 3, 2017 at 12:25 PM, Ether Jones <[hidden email]> wrote:

>
> Hello.
>
> I used glob to return a cell array of filenames.
>
> Now I want Octave to load and process each of those filenames, one at a time, and generate a separate output file for each input file.
>
> Can someone please point me in the right direction?
>
> Or is there a better way to do this?
>

​Something like that:

octave:1> fl = glob("*.h")
fl =
{
  [1,1] = config.h
  [2,1] = oct-conf-post.h
  [3,1] = octave-config.h
}

octave:2> for ii=1:rows(fl) disp(fl{ii}) endfor
config.h
oct-conf-post.h
octave-config.h


​Dmitri.






_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: processing filenames returned by glob

Ether Jones-2
In reply to this post by Ether Jones-2

On Wed, May 3, 2017 at 1:35 PM, Dmitri A. Sergatskov <[hidden email]> wrote:
for ii=1:rows(fl) disp(fl{ii}) endfor

​Thank you!

I think that's all I need to figure out the rest.



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave