Windows批处理文件,用于将某些文件类型从子目录复制到一个带有重命名的文件夹中 [英] Windows Batch file to copy certain file types from subdirectories to one folder with rename

查看:350
本文介绍了Windows批处理文件,用于将某些文件类型从子目录复制到一个带有重命名的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个批处理脚本,将位于G :(此处为随机命名子文件夹)\ 000.mpg的所有* .mpg文件复制到E:\ PVR.

I had tried to make a batch script that copies all *.mpg files located in G:(random named subfolders here)\000.mpg to E:\PVR.

for /R g:\ %%f in (*.mpg) do copy %%f E:\PVR\

问题在于源文件名相同,而它们是在所有子文件夹中具有相同名称的不同文件.该脚本会覆盖之前的文件,因此批量复制后我只有最后一个文件.请帮我用计数器之类的东西来重命名复制的文件.

the problem is that source file names are the same, while they are different files with same name in all subfolders. the script overwrites the previous file and so I only have the last file after batch copy. please help me rename copied files with a counter or something.

推荐答案

这应该可以解决问题.

@echo off
setlocal disableDelayedExpansion
set "src=."
set "dest=\temp"
set mask=*.mpg
for /r "%src%" %%F in (%mask%) do (
  if exist "%dest%\%%~nxF" (call :copyDup "%%F") else copy "%%F" "%dest%" >nul
)
exit /b

:copyDup
set /a cnt=1
:loop
set /a cnt+=1
if exist "%dest%\%~n1(%cnt%)%~x1" goto :loop
copy %1 "%dest%\%~n1(%cnt%)%~x1" >nul
exit /b

这篇关于Windows批处理文件,用于将某些文件类型从子目录复制到一个带有重命名的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆