Or better still

   chdir =: 1 !: 44                     NB. define "change working directory" 
verb
   getcwd =: 1 !: 43                    NB. define "query working directory" 
verb

   NB. Now start processing

   chdir '/home/fork/example'           NB. Set current working directory for 
file operations

   NB. Next check that everything worked OK when we tried to change the working 
directory
   NB. The return result may not necessarily be the identical string as used by 
chdir,
   NB. but I assume you already know that

   getcwd ''
/home/fork/example

   data =. fread 'stuff.csv'            NB. fread uses working directory so 
don't bother to give path
 
=============

Or for a simpler set and check you can do something like the following which 
executes the verbs chdir and then getcwd - 

   get...@chdir '/home/fork/example/'           NB. Set (and check) current 
working directory for file operations
/home/fork/example

                                                                NB. The return 
from chdir ('') is suitable as argument to getcwd


Ian

Ian Shannon
Landscape Modelling and Decision Support Section
Department of Environment, Climate Change & Water (NSW)
PO Box A290 Sydney South
NSW       1232
Phone: (02) 99 955 490
Mob:       0428 296 729  
email: Ian (determinant) Shannon (atop) environment (determinant) nsw 
(determinant) gov (determinant) au
web:   http://www.environment.nsw.gov.au

Please consider the environment before printing my email



-----Original Message-----
From: Henry Rich
Sent: Friday, 26 March 2010 6:24 AM
Subject: Re: [Jgeneral] "Current working directory" in J?

Look in the Vocabulary under Foreigns then Files (1!:n)

1!:43 ''    is like getcwd

1!:44  stringval   is like chdir

So what you described is

1!:44 '/home/fork/example'
data =. 1!:1 <((1!:43 '') , '/stuff.csv')


or you could write

data =. 1!:1 <'/home/fork/example/stuff.csv'

Henry Rich

Sprague, Webb (OFM) wrote:
> Hi all,
> 
> Does J have the notion of a current working directory, such that if one
> reads in data from a file that is specified with a relative path, J gets
> the working dir and finds the specified file relative to it.  
> 
> Along with this general knowledge, please tell me if there are functions
> to (1) return the string of the working directory, and (2) change to a
> working directory based on a string input.
> 
> Forgive me, but I will have to give an example in very non-APL ish
> pseudo code:
> 
> changdir ("/home/fork/example")
> data = readata(getcwd() + "/stuff.csv")  
> 
> data will then have the contents of file "/home/fork/example/stuff.csv".
> 
> If there is a page that documents this, a link would be much
> appreciated.  Thanks again for everyone's help and patience.
> 
> W
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
This email is intended for the addressee(s) named and may contain confidential 
and/or privileged information. 
If you are not the intended recipient, please notify the sender and then delete 
it immediately.
Any views expressed in this email are those of the individual sender except 
where the sender expressly and with authority states them to be the views of 
the Department of Environment, Climate Change & Water NSW.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to