batch-file - 从子目录中提取所有 .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
解决方案
我可能已经找到了解决方案(我必须复制我的 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 中导入数据,我更新了上面的代码片段以获得最终解决方案。
推荐阅读
- mysql - 如何在openempi中配置mysql?
- java - 在 NetBeans Swings 类中编辑代码
- python - 使用 Flask android 和网站部署的最佳方式
- vba - Can a character style be applied programmatically to a string before it is written to the Word document with VBA?
- gd - Coordinator : GD library already installed on server but show Your server does not support the GD function required to process this type of image
- algorithm - 为什么在多项式归约中 A _< B 总是正确的?
- python - 我如何使用 python 对一组数字进行洗牌。一个数字只允许从它的原点移动一步
- c++ - 使用 brew 在 MacOS 上的链接时缺少 boost ICU 正则表达式符号
- c - Can zeroisation of memory by xor-ing data with itself be optimized away in C?
- python - Why am I getting a string instead of a dictionary while reading a csv file in Python?