Add CSV CREATE_DIRECTORY=NO option
Feature description
Nope, there's absolutely no way to create CSV files that don't have the letters c, s, v in their suffix.
Our goal today is to create a CSV file, but with .ggg as it's suffix.
Alas, the moment there is no ".csv" sniffed as the destination file, then a decision is made to create a directory. Some kind of leftover logic probably stemming from back when shapefiles were the default output or something.
$ ogr2ogr -of CSV -q 順平.ggg data/順平.csv
$ ogr2ogr -of CSV -q 順平.csv data/順平.csv
$ ls 順平.* -Rog
-rw-r--r-- 1 199 05-11 03:28 順平.csv
順平.ggg:
-rw-r--r-- 1 199 05-11 03:29 順平.csv
One would think the -of might have helped convince the program that all I wanted was a plain .csv file, no bonus directory. But alas, the program has already made up its mind as to what I need and that's that.
Nope, the only workaround is
$ ogr2ogr -of CSV -q /vsistdout/ data/順平.csv > qqq.csv
$ ls -og qqq.csv
-rw-r--r-- 1 199 05-11 03:44 qqq.csv
(And of course one can always just use /bin/mv.)
GDAL 3.10.3, released 2025/04/01
There are easy workarounds.
Some kind of leftover logic probably stemming from back when shapefiles were the default output or something.
CSV driver supports also multilayer CSV so that all individual CSV files in a directory are seen as layers of one datasource. If you mean by leftover that it is something unintentional, I do not believe so.
ogr2ogr -of CSV dir poly.shp -nln test1
ogr2ogr -of CSV -update -append dir poly.shp -nln test2
ogrinfo dir
INFO: Open of `dir'
using driver `CSV' successful.
1: test1 (None)
2: test2 (None)
Okay that's great to know.
The problem is the CSV page does not mention all this. E.g., for somedir/*.csv where it is clear that the extension is .csv , for reading, and writing.
And that page also needs to mention the workaround to get around the bug that I reported above.
The problem is the CSV page does not mention all this.
I do see a trial to document that.
The datasource name may be either a single CSV file or point to a directory. For a directory to be recognised as a .csv datasource at least half the files in the directory need to have the extension .csv. One layer (table) is produced from each .csv file accessed. Starting with GDAL 3.7, pipe separated values files with a ".psv" extension are also recognized.
For my mind you did not report a bug, but it is opinion based. Feature request it is, for sure. CSV is not a bad extension for Comma Separated Values, but you are right that there is no CSV standard that mandates that, like GeoPackages must use .gpkg. The GeoCSV https://www.giswiki.ch/GeoCSV is only an open specification.