Windows CMD - 子文件夹循环

发布于 2024-12-17 12:24:50 字数 455 浏览 0 评论 0原文

我知道整个互联网上有很多关于 Windows 命令行的主题,但这对我来说仍然不够。 虽然当我用Python等实际编程语言编写循环来检查所有子文件夹时没有遇到任何问题,但我无法在Windows CMD下执行此操作。我真的很生气(如果我打扰了你,我真的很抱歉)。

我尝试了 /r 和 /d 开关,但我无法完成简单的操作 - 获取子文件夹中的文件列表:

for /d %%p in ("pathHERE*.jpg") DO echo %%p

我收到一条错误消息:

%%p此时出乎意料。

你能告诉我在哪里可以找到工作(通过互联网我发现了许多我无法运行的脚本 - 我知道批处理文件和从键盘手动键入的命令之间存在一些差异)操作示例,例如复制所有文件指定从所有子文件夹到另一个位置的扩展名或准备所有子文件夹的列表?

I know that over whole Internet there was many topics about windows command line, but it's still not enough for me.
Although I haven't got any problems when I'm writing loops in real programming language like Python to check all subfolders, I am unable to do it under windows CMD. I'm really annoyed (and really sorry if I am annoying you).

I tried both /r and /d switches, but I can't accomplish simply operation - get a list of files in subfolders:

for /d %%p in ("pathHERE*.jpg") DO echo %%p

I get an error message:

%%p was unexpected at this time.

Could you tell me where I can find WORKING (over Internet I found many script which I am unable to run - I am aware that there was some differencies between batch files and commands manually typed from keyboard) examples of operations such as copying all files with specified extension from all subfolders to another location or prepare list of all subfolders?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋心╮凉 2024-12-24 12:24:50

如果您从 cmd 窗口运行此行,则应更改为:

for /d %p in ("pathHERE*.jpg") DO echo %p

如果您想将此行放在批处理文件 (x.bat) 中,并且运行该文件,您应该在 var 名称中添加一个额外的 %,因此命令为:

for /d %%p in ("pathHERE*.jpg") DO echo %%p

运行批处理文件时 命令解释器删除任何 var 名称中的第一个 %。

if you are running this line from a cmd window you should change to:

for /d %p in ("pathHERE*.jpg") DO echo %p

if you want to place this line in a batch file (x.bat) and run that file you should add an additional % to the var names, so the command would be:

for /d %%p in ("pathHERE*.jpg") DO echo %%p

when running a batch file the command interpreter removes the first % from any var name.

放飞的风筝 2024-12-24 12:24:50

尝试在 DO 使用 %%p 时加上引号

for /d %%p in ("pathHERE*.jpg") DO echo "%%p"

Try placing quotes around your DO use of %%p

for /d %%p in ("pathHERE*.jpg") DO echo "%%p"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文