首页 > 解决方案 > 从子目录中提取所有 .img 文件

问题描述

我有一个目录,其中包含一些名为 *.data 的子目录,其中包含一个名为 Ratio.img 的文件、一个名为 Ratio.hdr 的文件和一个目录 vector_data。

这是我的设置:目录:

-ABC.data/-Ratio.img
    /-Ratio.hdr
    /-vector_data

-DEF.data/-Ratio.img
    /-Ratio.hdr
    /-vector_data

我想要一个命令行解决方案来从每个子目录中获取 Ratio.img,将其重命名为子目录的名称(不带 .data)并将其移动到目录本身。

我尝试了一些寻找 .img 图像并移动它们的东西,但我没有设法将重命名包含在文件名中。

# Unfortunately all those .img file are named Ratio, so they ask me to overwrite, what I clearly do not want to.
FOR /R %G in ("*.img") DO Move "%G" "G:\GRD_TEst\Products"

#I tried Renaming the Ratio.img-files, since I think I could work with them even if they are named blah.data.img
FOR /D %G in ("*.data") DO Rename "G:\GRD_TEst\Products\"%G"\Ratio.img" "G:\GRD_TEst\Products\"%G"\"%G".img"


# I also tried some "nesting" of for loops, but this did not lead to the output I wanted, basically create the path to my Ratio.img-File

for /D %G in (.data) do 
    FOR /D %X in ("Ratio.img") DO echo %G\%X

我希望输出像 dir:

-ABC.img
-ABC.data/Ratio.hdr
    /vector_data
-DEF.img
-DEF.data/Ratio.hdr
    /vector_data

标签: batch-filecmd

解决方案


我可能已经找到了解决方案(我必须复制我的 Ratio.img 文件,因为我没有进行备份:()

`for /D %%G in ("*.data") do (
    FOR /D %%I in (Ratio.img) DO Rename G:\GRD_TEst\Products\%%G\%%I %%G.img
    FOR /D %%H in (Ratio.hdr) DO Rename G:\GRD_TEst\Products\%%G\%%H %%G.hdr)`

这不起作用,它重命名了文件,但我不能这样使用它们,它们不能导入 ArcMap。移动将在第二步中完成。

编辑:在重命名 .hdr 之后,我终于可以在 ArcMap 中导入数据,我更新了上面的代码片段以获得最终解决方案。


推荐阅读