批处理文件,遍历文件并根据扩展名检查是否存在

Batch file, looping through files and check existence based on extensions

我对批处理文件还很陌生,所以这看起来有点菜鸟,但就是这样:) 我正在尝试对文件夹中的文件应用一些程序 - 遍历文件夹中的所有文件,没有扩展名,或具有 .csv 扩展名 (这部分我已经想通了:

for %%i in (*.csv *.) do <command> %%i -s

但是如果我在那个文件夹中已经有一个 %%i.txt 文件,我想跳过这个(即 - 只对没有相应 .txt 文件 int 文件夹的文件执行命令)。 这是我不太明白的部分...

像这样:

for %%i in (*.csv *.) do if not exist "%%~ni.txt" <command> %%i -s

适用于此:

for %%i in (*.csv *.) do if not exist "%%~ni.txt" <command> %%i -s

您需要使用替换修饰符 "~n" 将变量 "i" 限制为仅文件名,而不是扩展名。更多细节在这里: MS Win XP Documentation