Page 1 of 1

Automatically read file names in a folder

Posted: Thu Mar 11, 2010 12:53 pm
by tchaithonov
Hi Guys,

I have yet another weird question. If I tell eviews the location of a particular folder, is there a way to make it spell out all the file names within a folder and record the names into a table or something? Let me give you an example:

If I have a folder called "C:/eviews7/ABC/" and there are n number of csv files in it, is there a way to write a piece of code such that eviews would create a (nx1) table where each cell contains a unique file name (stripped off the .csv part, which I know how to do as long as I could read it one by one as a string)?

If you have any ideas/hints/clues, please let me know. Thanks.

Tchaithonov

Re: Automatically read file names in a folder

Posted: Thu Mar 11, 2010 2:41 pm
by EViews Glenn
The EViews 7 function @wdir should be enough to get you going.

Re: Automatically read file names in a folder

Posted: Thu Mar 11, 2010 2:43 pm
by EViews Gareth
Before remembering the @wdir command, I came up with a manual way of doing it, which is clearly beaten by @wdir, but is instructional nevertheless:

Code: Select all

create u 10 cd c:\temp shell dir /b > dir.txt text dirlist dirlist.append(file) dir.txt dirlist.svector filelist
which will create an svector called filelist containing all the files in the directory c:\temp

Re: Automatically read file names in a folder

Posted: Thu Mar 11, 2010 3:04 pm
by EViews Gareth
You could also use the example in the manual :D :

Code: Select all

shell(out=flist) dir /b
which will make a table object containing the directory contents.

Re: Automatically read file names in a folder

Posted: Fri Mar 12, 2010 1:48 pm
by tchaithonov
Excellent suggestions guys! Thanks very much indeed. I will try this out once I finish dealing with another issue...