Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何为每个子文件夹运行命令_Batch File_Cmd_Batch Processing - Fatal编程技术网

Batch file 如何为每个子文件夹运行命令

Batch file 如何为每个子文件夹运行命令,batch-file,cmd,batch-processing,Batch File,Cmd,Batch Processing,我有一个批处理文件,可以将文件夹中找到的所有图片重命名为系列名称,如0001.jpg 0002.jpg 003.jpg 此批处理文件的代码为: set cnt=0 FOR /R d:\all\photos1\ %%a in (Graphic*.jpg) do call :renfile "%%a" goto :eof :renfile set /a cnt += 1 set padCnt=0000%cnt% ren %1 %padCnt:~-4%%~x1 问题是,我的父文件夹“all”

我有一个批处理文件,可以将文件夹中找到的所有图片重命名为系列名称,如0001.jpg 0002.jpg 003.jpg

此批处理文件的代码为:

set cnt=0
FOR /R d:\all\photos1\    %%a in (Graphic*.jpg) do call :renfile "%%a"
goto :eof

:renfile
set /a cnt += 1
set padCnt=0000%cnt%
ren %1 %padCnt:~-4%%~x1
问题是,我的父文件夹“all”中有许多文件夹和子文件夹,因此我必须为每个文件夹创建一个批处理文件,因此我需要创建一个批处理文件,该文件将查看父文件夹“all”中的所有文件夹和子文件夹,并运行我提到的命令重命名其中的图片。

您尝试过吗

FOR /R d:\all\ %%a in (Graphic*.jpg) do call :renfile "%%a"
(对于测试,我非常想
ECHO
使用
ren
命令…)


对于未注明的重置编号问题

set lastdir=:
FOR /R d:\all\    %%a in (Graphic*.jpg) do call :renfile "%%a"
goto :eof

:renfile
if NOT "%lastdir%"=="%~p1" set /a cnt=0&set "lastdir=%~p1"
set /a cnt += 1
set padCnt=0000%cnt%
ren %1 %padCnt:~-4%%~x1

(air代码-应该可以工作)

可以,但问题是每个文件夹的序列号没有重置,我希望每个文件夹都有自己的名称序列,从0001.jpg开始……感谢您的努力,但是数字重置不起作用。如果不重置数字,它仍然可以工作是-两个小故障。首先,我把
photos1\
放在了
FOR/R
中,在
IF
行中省略了
NOT
。现在修复。。。