问题描述
我正在运行类似
for %j in (c:\user\data) do if not %j == Important del %i
以便除此文件外的所有文件都被删除.但是,重要的是,在运行此文件之前,我想确保脚本只会删除我要删除的文件,因此,我想查看文件在运行前是否受到影响,因此尝试使用回声为
so that all files get deleted except this one Important however, before I run this I wanted to make sure that script will only delete which I meant to hence, I wanted to see the files being affected before I run so I tried using echo as
for %i in ("c:\user\data") do echo %i
但是这似乎不起作用,我希望看到该目录中的所有文件,以便可以确定文件是否受到影响,但看不到任何东西,没有错误或任何东西.看起来CMD打开和关闭非常快.有人可以帮我吗..
but this does not seem working, I am expecting to see all the files in this directory so that I would be sure about the files being affected but I do not see anything, no error or anything. It just looks CMD opens and closes very fast. Can someone please help me..
推荐答案
您只需要根据您的条件引用目录的内容,而不仅仅是目录本身.从命令行:
You simply need to refer to the contents of the directory in your condition, rather than merely the directory itself. From command line:
for %i in (c:\user\data\*) do echo %i
如果要在批处理文件中执行此操作,则需要为循环变量添加双百分号:
And if you're doing it inside a batch file, then you need to add double percent signs for your loop variable:
for %%i in (c:\user\data\*) do echo %%i
有关语法的更多信息此处.
这篇关于通过批处理文件删除文件之前回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!