[英]create windows 8 batch file to copy, rename and save files from sub directories recursively
I'm trying to copy thousands of image files and rename them with the name of the folder they are in. The file structure is:- 我正在尝试复制数千个图像文件,并使用它们所在的文件夹名称重命名它们。文件结构为: -
C:\pictures\kitcam\1\master_01.jpg
C:\pictures\kitcam\1\master_02.jpg
C:\pictures\kitcam\2\master_01.jpg
C:\pictures\kitcam\3\master_01.jpg
C:\pictures\kitcam\3001\master_01.jpg
I would like to create a new directory C:\\pictures\\kitcam\\all
and copy and rename the files above to the following naming convention:- 我想创建一个新目录
C:\\pictures\\kitcam\\all
并将上面的文件复制并重命名为以下命名约定: -
c:\\pictures\\kitcam\\all\\[directoryname]_filename]
(pad directory name to 4 digits so that the director name 1 becomes 0001 etc) (将目录名称填充为4位,以便导演名称1变为0001等)
for example:- 例如:-
C:\pictures\kitcam\all\0001_master_01.jpg
Jonathan 乔纳森
@ECHO OFF &SETLOCAL
SET "startfolder=C:\pictures\kitcam"
SET "targetfolder=C:\pictures\kitcam\all"
FOR /r "%startfolder%" %%a IN (*.jpg) DO (
SET "fname=%%~nxa"
SET "fpath=%%~fa"
FOR /f "delims=" %%b IN ("%%~dpa.") DO SET "nname=000%%~nxb"
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO MOVE "!fpath!" "%targetfolder%\!nname:~-4!_!fname!"
ENDLOCAL
)
Look at the output and remove the word echo
before move
if it looks good. 如果看起来不错,请查看输出并在
move
之前删除单词echo
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.