Hi Bart,
A getfolders() function has been on the to-do list for a while --- I'll move it
to the top.
Below is an Ox program that gets the folders under Windows. It is a bit of a
hack, and probably not a very robust solution, but it works on my machine
(Windows XP).
Of course, Jaap's suggestion would be more robust and avoid the temporary file.
Best, Jurgen
//////////////////////////////////////////////////////////
#include <oxstd.h>
GetFoldersWindows()
{
// use TEMP environment folder to store output of dir
decl tmpfile = getenv("TEMP") ~ "\\folders.lst";
// only directories, short output; redirect to the tmpfile
decl ret = systemcall("dir /B/AD *.* > " ~ tmpfile);
if (ret != 0)
return {};
// now open and read the file
decl file = fopen(tmpfile, "r");
if (!isfile(file))
return {};
decl asfolders = {}, sfile;
while (!feof(file))
{
// read the file line by line until the end
if (fscan(file, "%z", &sfile) == 1)
asfolders ~= sfile;
}
// return as an array of strings
return asfolders;
}
main()
{
// chdir("D:\\Waste");
println("Current folder: ", getcwd());
decl asfolders = GetFoldersWindows();
if (sizeof(asfolders))
println("Subfolders of current folder: ", asfolders);
else
println("No subfolders found");
}
//////////////////////////////////////////////////////////
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
oxoxoxox US OxMetrics user conference 2010
oxoxoxox George Washington University, Washington DC
oxoxoxox 18-19 March 2010
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Dr Jurgen A Doornik
University of Oxford, Nuffield College, Oxford OX1 1NF
tel. UK: +44-1865-278610 fax +44-1865-278621
http://www.doornik.com
http://www.oxmetrics.net
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Bart Frijns wrote:
> Hi,
>
> I have a question about how to get an array of folders in Ox. I can use
> the command getfiles("*.*") to get all files and getcwd() to get the
> current folder, but I cannot see the other folders I have. Is there a
> solution to this?
>
> Thanks,
>
> Bart
|