Automatically read file names in a folder

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

tchaithonov
Posts: 168
Joined: Mon Apr 13, 2009 7:39 am
Location: New York City

Automatically read file names in a folder

Postby tchaithonov » Thu Mar 11, 2010 12:53 pm

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

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Automatically read file names in a folder

Postby EViews Glenn » Thu Mar 11, 2010 2:41 pm

The EViews 7 function @wdir should be enough to get you going.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13602
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatically read file names in a folder

Postby EViews Gareth » Thu Mar 11, 2010 2:43 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13602
Joined: Tue Sep 16, 2008 5:38 pm

Re: Automatically read file names in a folder

Postby EViews Gareth » Thu Mar 11, 2010 3:04 pm

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.

tchaithonov
Posts: 168
Joined: Mon Apr 13, 2009 7:39 am
Location: New York City

Re: Automatically read file names in a folder

Postby tchaithonov » Fri Mar 12, 2010 1:48 pm

Excellent suggestions guys! Thanks very much indeed. I will try this out once I finish dealing with another issue...


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests