返回列表 发帖

(已解决)合并2个文件夹内的BIN文件。(50元)

本帖最后由 81442818 于 2024-12-5 20:27 编辑

每次从文件夹1和文件夹2分别取出一个文件合并成一个新的文件。
删除文件夹1/2内合并过的文件。
联系QQ 353560609

<# :
cls&echo off&cd /d "%~dp0"
path %SYSTEMROOT%\System32\WindowsPowerShell\v1.0;%path%
set "current=%cd%"
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
pause
exit
#>
$current=($env:current).trimend('\');
$folder1=$current+"\1";
$folder2=$current+"\2";
$output=$current+"\3";
if(-not (test-path -literal $folder1)){write-host ('"'+$folder1+'" path error or not exist');exit;}
if(-not (test-path -literal $folder2)){write-host ('"'+$folder2+'" path error or not exist');exit;}
if(-not (test-path -literal $output)){[void][IO.Directory]::CreateDirectory($output);}
$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;
$arr=@(dir -literal $folder1|?{('.bin' -ne $_.Extension) -and ($_ -is [System.IO.FileInfo])});
$brr=@(dir -literal $folder2|?{('.bin' -ne $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $arr.length;$i++){
    remove-item -literal $arr[$i].FullName -force -ErrorAction SilentlyContinue;
}
for($i=0;$i -lt $brr.length;$i++){
    remove-item -literal $brr[$i].FullName -force -ErrorAction SilentlyContinue;
}
$arr=@(dir -literal $folder1|?{('.bin' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
$brr=@(dir -literal $folder2|?{('.bin' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
if(($arr.length -ge 1) -and ($brr.length -ge 1)){
    $files1=[ExpDir]::Sort($arr);
    $files2=[ExpDir]::Sort($brr);
    for($i=0;$i -lt $files1.count;$i++){
        if($i -lt $files2.count){
            $f1=get-item -literal ($folder1+'\'+$files1[$i]) -force;
            $f2=get-item -literal ($folder2+'\'+$files2[$i]) -force;
            write-host $f1.FullName;
            write-host $f2.FullName;
            $b1=[IO.File]::ReadAllBytes($f1.FullName);
            $b2=[IO.File]::ReadAllBytes($f2.FullName);
            $nb=$b2+$b1;
            $newfile=$output+'\ALL_'+$f2.Name;
            [IO.File]::WriteAllBytes($newfile, $nb);
            remove-item -literal $f1.FullName -force -ErrorAction SilentlyContinue;
            remove-item -literal $f2.FullName -force -ErrorAction SilentlyContinue;
            break;
        }
    }
}COPY
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表