本文介绍了在文件系统的每个文件夹上执行复杂的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常需要执行以下命令来压缩文件夹中的所有PNG文件:

I need to execute often the following command which compresses all the PNG files in a folder:

for %i in (*.png) do pngout.exe "%i" /kp

因此,我已将此命令添加到文件png.cmd中,并将该文件夹添加到系统PATH中.

So I have added this command in a file png.cmd and added the folder to the system PATH.

但是,当我从文件系统中的某个点执行命令(png.cmd)时,出现以下错误:

However when I execute the command (png.cmd) from a point in my file system, I get the following error:

C:\Users\Desktop>png  
i" /kp was unexpected at this time.

是否有解决此问题的方法,我还在考虑shell将在哪里执行png.cmd命令?在创建png.cmd文件的路径中?我需要在当前的Shell所在的PATH中执行它.
任何想法?非常感谢

Is there a way to fix this problem, also I'm thinking where the shell is going to execute the png.cmd command ? In the path where I've created the png.cmd file ? I'd need to execute it in the current PATH where I'm with the shell.
Any idea?Thanks a alot

推荐答案

当您使用时,您的语法错误是由于在 for 循环变量中仅使用1个引起的批处理文件,您需要使用2来转义第一个.

Your syntax error is caused by using only 1 % in your for loop variable, when you use a batch file you need to use 2 to escape the first one.

for %%i in (*.png) do pngout.exe "%%i" /kp

关于您的路径问题,请先解决此问题,然后查看是否仍然是问题.

With regards to your path question, fix this first, then see if it's still an issue.

这篇关于在文件系统的每个文件夹上执行复杂的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 07:53