windowsbashsyntaxfilenamesogr2ogr

Filename and path link in batch


So I have a line of code in .bat using ogr2ogr geospatial tool:

for /R %F in (*_gpx.shp) do ogr2ogr -update -append "%~dpnF.shp" "______________"

In the "___________"space I need to specify a file, that:

-is in the same folder as *_gpx.shp

-beginning of its name is equal to the gpx.shp, but the ending is not (it's a pair of "sametext_abc_gpx.shp" and "sametext_bby.shp")

-I have plenty of these pairs and their names aren't of same length, but have same endings (only abc and bby)

My first guess was

"*_bby.shp"

But it didn't work for me. I tried with addressing it with %~dpF, removing last 7 characters ("abc_gpx") and adding "bby", but I'm not so fluent in bash syntax.


Solution

  • Well, that appeared to be the solution:

    "%~dpF*_bby.shp"

    for Windows CMD, for batch files obviously

    "%%~dpF*_bby.shp"

    That is disk letter, path and letter indicating File which is a wildcard * plus the ending.