1

我有几个 tif 格式的文件。我想将它们翻译成 ENVI 格式。我成功处理了一个文件,但我想处理目录中的其余文件。

   the first file in the directory is:Ser_W55_20100101_A.tif.
   the second file in the directory is:Ser_W55_20100102_A.tif    and so on .....

我在 Windows 上工作,所以我只是启动 cmd 然后编写命令:

 C:\Users>gdal_translate -of "ENVI" D:\Ser_W55_20100101_A.tif D:\Ser_W55_20100101_A.img

这工作得很好。请对如何对所有文件执行此操作并返回相同名称的任何想法(从 (tif) 更改为 ENVI)

4

1 回答 1

4

You can make a batch file for this, do something like:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET mypath=D:\test\

FOR /F %%i IN ('DIR /B %mypath%*.tif') DO (

    SET infile=%%i
    SET outfile=!infile:.tif=.img!

    gdal_translate -of "ENVI" %mypath%!infile! %mypath%!outfile!

)

This only runs in de current directory, if you want to include subfolders, add the /S flag to the dir statement. I might be good to check whats happening at first, to do so you can add a ECHO in front of the gdal cmd, so ECHO gdal_translate..., and add a PAUSE at the end. That way it will only print the commands to the console instead of actually running them.

于 2013-05-23T06:27:17.553 回答