批处理-Forfiles循环使用多种文件类型 [英] Batch - Forfiles in loop with multiple file types

查看:456
本文介绍了批处理-Forfiles循环使用多种文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作用于转换某些文件类型的批处理文件.因此,我不会在代码中放置更多无用的循环,而是希望将其放入一个循环中.

I am trying to make a batch file for converting certain file types. So I don't put more useless loops in the code, I wanted to put it into one loop.

到目前为止,这是我的代码:

This is my code so far:

cd "%inputdir%"
setlocal disableDelayedExpansion
for /f "delims=" %%A in ('forfiles /s /m *.tga /c "cmd /c echo @relpath"') do (
  set "file=%%~A"
  setlocal enableDelayedExpansion
  set filenametmp=%outputdir%!file:~1,-4!.paa

  setlocal enableDelayedExpansion
  For %%A in ("!filenametmp!") do (
    Set foldertmp=%%~dpA
  )

  setlocal enableDelayedExpansion
  IF NOT EXIST "!foldertmp!" (
    mkdir "!foldertmp!"
  )
  endlocal

  cd !Convertfolder!
  Pal2PacE %inputdir%!file:~1! !filenametmp!
)

我使用了此答案来改善for循环进入:

I used this answer to improve the for loop into:

for /f "delims=" %%A in ('for %%G in (.tga, .png) do 'forfiles /s /m *%%G /c "cmd /c echo @relpath"'') do (... 

不幸的是,它引发了此错误:

Unfortunately, it throws this error:

System cannot find file for %G in...

有人知道如何解决吗?

推荐答案

如果我正确理解,我认为这段代码将满足您的要求.

If I'm understanding correctly, I think this code will do what you want.

for %%G in (.tga, .png) do (
  for /f "delims=" %%A in ('forfiles /s /m *%%G /c "cmd /c echo @relpath"') do (
    REM The ECHO below is just for testing.
    REM Put the code from inside your FOR loop here.
    ECHO %%A
  )
)

这篇关于批处理-Forfiles循环使用多种文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆