Windows批处理文件来复制和重复保持 [英] Windows batch file to copy and keep duplicates

查看:170
本文介绍了Windows批处理文件来复制和重复保持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有图像的很多文件夹,我想创建一个批处理文件,可以浏览所有这些目录及其子目录,每一个影像(所有文件放在同一文件夹中)复制到一个新的文件夹。我有这方面的工作使用如下:

I have many folders of images, and I want to create a batch file that can look through all these directories and their subdirectories, and copy every image to a single new folder (all files in the same folder). I have this working using the below:

md "My new folder"
for /D %i in (*) do copy "%i\*" ".\My New Folder"

不过,我也想保持文件,重复(例如,如果文件夹1和文件夹2双方都称为图像001.JPG,我想都复制到新的文件夹)。这并不重要,我的新文件名是什么!有:

however, I also want to keep files with duplicates (for example if folder1 and folder2 both have images called 001.jpg, i want both copied to the new folder). It doesn't matter to me what the new filenames are! Having:

001.jpg
001(1).jpg
001(2).jpg

将是巨大的,但即使只是重命名每一个文件与增量计数和结束了:

would be great, but even just renaming every single file with an incremental count and ending up with:

1.jpg
2.jpg
3.jpg
etc

将被罚款了。我需要它只是使用标准的蝙蝠/ .CMD文件,虽然,没有外部的软件。

would be fine too. I need it just using a standard .bat/.cmd file though, no external software.

感谢您的帮助!

推荐答案

这应该为你工作。追加后延一些,但你可以轻松移动任何地方。我复制从\\ SRC目录文件,因为如果你有在同一水平作为批处理文件中的消息人士透露,该批处理文件试图评估过test_folder。最好的选择是硬code test_folder所以它的地方,也不会由DIR / S / B ...命令evaulated

This should work for you. It appends a number after the extension, but you could easily move that anywhere. I copied files from the .\src dir, since if you have the sources at the same level as the batch file, the batch file tries to evaluate test_folder too. The best choice would be to hardcode test_folder so it is somewhere that won't be evaulated by the DIR /S /B... command

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set TESTFOLDER=test_folder
md "%TESTFOLDER%"

set /a counter=0
FOR /F "tokens=*" %%i IN ('DIR /S /B /A-D .\src\*') DO FOR /F "tokens=*" %%j IN ('DIR /B "%%i"') DO IF EXIST ".\%TESTFOLDER%\%%j" (
        set /a counter=!counter!+1
        echo folder: %TESTFOLDER%
        copy "%%i" ".\%TESTFOLDER%\%%j_!counter!"
    ) ELSE copy "%%i" ".\%TESTFOLDER%\%%j"
:eof

这篇关于Windows批处理文件来复制和重复保持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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