用于创建文件副本的批处理文件

时间:2017-03-27 10:05:41

标签: batch-file copy numbered-list

我想创建一个视频文件(.mp4)格式的副本,每个副本交替编号,例如:文件显示为01.mp4,因此下一个副本应命名为03.mp4 05.mp4 07 .mp4等 任何帮助是极大的赞赏。 谢谢,

1 个答案:

答案 0 :(得分:0)

如果您的意思是要复制相同的文件, 您可以使用批处理脚本尝试类似的东西:

@echo off
set Source=C:\TEMP\MyFile.mp4
set Destination=E:\MyData\
set Filename=MyDoc
set a=1

:loop
if exist %Destination%\%Filename%(%a%).txt set /a a+=1 && goto :loop
copy %Source% %Destination%\%Filename%(%a%).mp4
pause

注意: 如果这不是您想要的,只需编辑您的问题并在您的请求中更明确,并尝试向我们提供代码以了解更多您的目标和你的问题!

编辑于2017年3月27日@ 15:00

这是使用数组进行复制的另一种方法:

@echo off
Title Search for images files
mode con cols=75 lines=5 & Color 0A
set "Folder=%USERPROFILE%\Videos"
set "Destination=%userprofile%\desktop\TestCopy"
If Not Exist "%Destination%" MD "%Destination%
set "Count=0"
set "EXT=mp4"
Set "Msg=Please wait a while scanning for"
Setlocal Enabledelayedexpansion
For %%a in (%EXT%) Do ( 
    FOR /f "delims=" %%f IN ('dir /a-d /b /s "%Folder%\*.%%a"') DO (
        Rem We increment the variable Count
        SET /a "Count+=1"
        rem populate the array variable list with the name of files with their extensions
        set "list[!Count!]=%%~nxf"
        rem populate the array variable list with the name of files without their extensions
        set "listName[!Count!]=%%~nf"
        Call :Scanning "%%~nxf"
        rem populate the array variable listpath with the whole path of files
        set "listpath[!Count!]=%%~dpFf"
    )
)
for /L %%i in (1,1,%Count%) do (
    Copy /y "!listpath[%%i]!" "%Destination%\%%i_!listName[%%i]!.mp4">nul 2>&1
)
Explorer "%Destination%" & Exit
::****************************************************************************
:Scanning %1
Cls
echo( & echo(
echo            %Msg% %1
exit /b
::****************************************************************************