help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable for directory in cd


From: Joseph Craig
Subject: Re: variable for directory in cd
Date: Tue, 9 Mar 2010 12:50:04 -0700

thanks David.  worked!

Joe
On Mar 9, 2010, at 12:38 PM, David Grundberg wrote:

> Blitz skrev:
>> I'm trying to use the UNIX command "cd" to jump in and out of directories
>> programmatically in Octave.  How do I use my variable in the cd command?
>> 
>> trying...
>> 
>> dirs = ls -d */
>> for j = 1:length(dirs(:,1)),
>>     cd dirs(j,:)   % line I'm having trouble with
>>     % do stuff
>>     cd ..
>> end
>> 
>> I'm running Octave 3.0.1 under Ubuntu
>> 
>> thanks!
>>  
> 
> You're calling cd with command call syntax. Can't reference variables then. 
> You have to use expression statements if you want to use variable values.
> 
> So you're doing
> 
>   cd dirs(j,:)
> 
> which is evaluated as
> 
>   cd ("dirs(j,:)")
> 
> which won't work. You have to do it like this:
> 
>   cd (dirs(j, :))
> 
> Also, I'd recommend from moving away from
> 
>   dirs = ls -d */
> 
> and using
> 
>   dirs = dir ();
> 
> with extra logic instead. Return values from command calls aren't supported 
> in 3.2 IIRC.
> 
> hth,
> David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]