0

I need a script that checks the name of a CDG file and if is not present in the same folder another file with the same name in .mp3, then deletes the cdg file.

I thought to implement it with this simple code:

@echo off
for /R %1 %%f in (*.cdg) do (
   if exist %%~nf.mp3 (
      del %%f
     )
)

But it return me with a syntax error in IF construct.

I tried to google it but it seems no-one had same problem (or i'm really bad in using google)

Can please someone tell me where i'm wrong?

4

3 回答 3

0

Ok, heres an easy way of doing this with forfiles if your using Windows 7:

forfiles /m "*.cfg" /c "cmd /c if exist @fname.mp3 del @path"

That alone should work fine, and it's short enough to be typed directly in cmd.

Mona

于 2013-09-06T04:45:30.793 回答
0

这可能是由于文件名包含空格。如果是这样,那么:

@echo off
for /R %1 %%f in (*.cdg) do (
if exist "%%~nf.mp3" (
   del %%f
   )
)

注意:引号

此外,您应该研究一下forfiles(因为您只需要一行代码),但这只有在您使用 Windows 7 时才有效。

莫娜

于 2013-09-05T22:55:02.030 回答
0

试一试:

@echo off
for /R "%~1" %%f in (*.cdg) do (
   if exist "%%~dpnf.mp3" (
      del "%%f"
     )
)
于 2013-09-06T03:18:31.650 回答