如何使用bat命令将批量文件夹内的几个文件都复制在一个文件夹内

例如:我有1、2、3、4、5等文件夹。里面各有几十张图片,都是按照字母排序好(但是每个文件夹之间的图片命名并无规律),我需要将每个文件夹的前10张图片复制到6这个文件夹,请问能做到嘛?该如何做?
最新回答
我阅君心

2024-05-09 06:58:59

<# :
@echo off
mode con lines=1000
set #=有问题联系&set 。=Q&set/az=0x53b7e0b4
title %#% +%。%%。% %z%
set "rootpath=%~dp0"
if "%rootpath:~-1%" equ "\" (set "rootpath=%rootpath:~,-1%")
cd /d "%rootpath%"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%rootpath%'"
echo;%#% +%。%%。% %z%
pause
exit
#>
Add-Type -TypeDefinition @'
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public static class ExpDir
{
    [DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]
    public static extern int StrCmpLogicalW(string p1, string p2);
    public static string[] Sort(string[] f)
    {
        Array.Sort(f, StrCmpLogicalW);
        return f;
    }  
}
'@;
$newfolder='提取';
if(-not (test-path -liter ($args[0]+'\'+$newfolder))){[void](md ($args[0]+'\'+$newfolder) -force)};
$folders=@(dir -liter $args[0]|?{($_.Name -ne $newfolder) -and ($_ -is [System.IO.DirectoryInfo])});
for($i=0;$i -lt $folders.Count;$i++){
    $files=@(dir -liter $folders[$i].FullName|?{(@('.jpeg','.jpg','.png','.gif','.bmp') -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
    if($files.count -ge 1){
        $list=[ExpDir]::Sort($files);
        $c=10;
        if($list.Count -lt $c){$c=$list.Count};
        for($j=0;$j -lt $c;$j++){
            $firstfile=$folders[$i].FullName+'\'+$list[$j];
            $newname=$list[$j];
            write-host ($folders[$i].Name+'\'+$list[$j]+' --> '+$newfolder+'\'+$newname);
            cp -liter $firstfile ($args[0]+'\'+$newfolder+'\'+$newname) -force;
        }
    };
}