dir and path help

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

dir and path help

dirac
Hi everyone,

I want to do some batch analysis i.e. I want to operate some function on a whole folder. In the function I need to input the file name like so:

 >>Function(filename)

I can see that something like:

 >>a=dir('*.dat')

will list all of the files in the directory, but I want to perform this function on another folder where the source files are kept. Is this possible? I was looking in to the functions path and addpath, but cant seem to get anywhere.

Thanks in advance :)

Martin
Still learning everyday.
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

bpabbott
Administrator
On 07 Sep, 2010,at 10:41 AM, dirac <[hidden email]> wrote:

Hi everyone,

I want to do some batch analysis i.e. I want to operate some function on a
whole folder. In the function I need to input the file name like so:

>>Function(filename)

I can see that something like:

>>a=dir('*.dat')

will list all of the files in the directory, but I want to perform this
function on another folder where the source files are kept. Is this
possible? I was looking in to the functions path and addpath, but cant seem
to get anywhere.

Thanks in advance :)

Martin
 
I'm not sure I understand exactly what you want to do ... but if the path to your folder is defined by ...

path_to_folder = "/Users/Martin/myfolder";

you can get the list of files by ...

a = dir (strcat (path_to_folder, filesep, "*.dat"))

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

dirac
Hi Ban,

Thanks for the reply that is what I wanted to do, basically use the dir function on another file. I have used the help function for the strcat bit but I was wondering what the filesep bit did...

Sorry if that is a really dumb question!

MA
Still learning everyday.
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

andy buckle
> Thanks for the reply that is what I wanted to do, basically use the dir
> function on another file. I have used the help function for the strcat bit
> but I was wondering what the filesep bit did...
>
> Sorry if that is a really dumb question!

filesep is a function. That may not be obvious from the way Ben typed
it. eg this will do the same thing

a = dir (strcat (path_to_folder, filesep(), "*.dat"))

type this at the octave prompt to find out more.

help filesep

--
/* andy buckle */
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

dirac
It was a silly question, as soon as I posted the question I thought to google it, found out more about it and did the whole help filesep! It is all a learning curve!

Cheers Andy
MA
Still learning everyday.
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

bpabbott
Administrator
In reply to this post by dirac
On 07 Sep, 2010,at 11:41 AM, dirac <[hidden email]> wrote:


Hi Ban,

Thanks for the reply that is what I wanted to do, basically use the dir
function on another file. I have used the help function for the strcat bit
but I was wondering what the filesep bit did...

Sorry if that is a really dumb question!

MA
 
The filesep() returns the character used to separate directories in a path statement.

On unix filesep = "/"

On DOS filesep = "\", recent versions of Windows accepts both.

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

dirac
Ahhh Cheers Ben (spelt your name correctly this time!),

so the STRCAT bit is basically concentrates the path_to_file, the \ from filesep and the file extension, which then can be put in to dir?

Cheers
MA
Still learning everyday.
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

bpabbott
Administrator
On 07 Sep, 2010,at 12:12 PM, dirac <[hidden email]> wrote:


Ahhh Cheers Ben (spelt your name correctly this time!),

so the STRCAT bit is basically concentrates the path_to_file, the \ from
filesep and the file extension, which then can be put in to dir?

Cheers
MA
 

Yes, "strcat" concatenates strings while stripping off trailing spaces off each argument.

Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: dir and path help

dirac
Thanks mate, this works brilliantly. Now all I need to do it learn to manage the data that I generate from doing things in batches and I'll be sorted!
Still learning everyday.