批量移动多个文件到多个文件夹的bat命令,详细如下:

一个文件夹里有多个文件:
001.mp4
002.mp4
003.mp4
004.mp4
......
将指定数量的文件移动(分发)到其他指定的多个文件夹里,文件夹已提前建好

不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件和文件夹放一起双击运行<# :
cls&echo off&cd /d "%~dp0"&mode con lines=5000
rem 将当前目录里的多个mp4文件按照指定数量平分到多个不同文件夹里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "current=%cd%"
echo;%#% +%$%%$%/%_% %z%
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
pause
exit
#>
$count=4;

$folder=@"
文件夹1
文件夹2
文件夹3
文件夹4
文件夹N
"@;


$codes=@'
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;
    }  
}
'@;
Add-Type -TypeDefinition $codes;

$b=[Convert]::FromBase64String("IC0tPiA=");
$c=[Text.Encoding]::Default.GetString($b);
$arr=$folder.trim() -split '[\r\n]+';
$current=$env:current;
$files=@(dir -literal $current|?{(@('.mp4') -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
if($files.length -ge 1){
    $n=0;
    $brr=[ExpDir]::Sort($files);
    for($i=0;$i -lt $brr.count;$i++){
        if($n -lt $arr.length){
            $fd=$arr[$n].trim();
            $newfolder=$current+'\'+$fd;
            $oldfile=$current+'\'+$brr[$i];
            $newfile=$newfolder+'\'+$brr[$i];
            write-host ($brr[$i]+$c+$fd);
        }
        if((($i+1) % $count) -eq 0){$n++;}
    }
}

追问

你好,运行之后文件没有移动,CMD运行框里看起来像是正确的,但是文件却没有移动

追答

按运行代码后窗口标题栏中的提示联系我

温馨提示:答案为网友推荐,仅供参考
第1个回答  2022-05-19
MOVE是移动文件的命令,根据例子,可以使用命令:
move *.mp4 分发\
或者:

move ???.mp4 分发\追问

不行呀,无法实现上述分发的功能

追答

请上三图,一是代码,二是执行前后文件夹

相似回答