Writing a table to a file using D3 pick

475 views Asked by At

In D3, suppose I have a file called foo and I want to write the contents of the file out to /var/tmp/bar. The documentation leads me to believe that it should be possible to make D3 write the file to the file system by changing the D pointer into a Q pointer, but I can't figure out how to make this happen.

1

There are 1 answers

2
TonyG On BEST ANSWER

You can do this at least a few ways.

1) You don't want to change a d-pointer to a q-pointer, you just want to create a q-pointer. In other words there's no need to have a d-pointer first to access the host file system. So your q-pointer called 'bar' will look like this:

Q
/var/tmp/bar

With that you can simply:

copy foo
to: (bar

Note that in this case 'bar' is a host OS folder/directory, not a file. A D3 'file' is a table that has multiple records. That translates to a host OS directory with multiple files.

Options are available on the Copy command to suppress the display of item IDs (keys) as records are copied (see docs).

2) You don't even need a q-pointer:

copy foo
to: (/var/tmp/bar

3) Similarly in code you can use the q-pointer or you can use the direct path:

open 'bar' to f.bar1 ...
open '/var/tmp/bar' to f.bar2 ...

==

The path syntax is using a mechanism called the OSFI (see docs). With this syntax you can specify a driver. The default driver called "unix:" converts attribute marks to the *nix EOL which is a line-feed x0A. If you're on Windows the default is "dos:" which converts attribute marks to CRLF x0D0A. You can force a non-default by preceding the path with the driver. So to create a DOS-format file in Unix/Linux, use dos:/var/tmp/bar. The default drivers also convert between tab and 4-spaces (see docs). Values and subvalues are not converted but a new driver can be created to do so. Use the 'bin:' driver to avoid conversions, so bin:/var/tmp/bar will not convert @am (xFE) to x0A, etc.

If you need more detail I'll be happy to add to this.