level 1
需求是这样的,一个文件夹里有100个TXT文档和300张照片,可以有BAT 程序 自动生成100个文件夹,每个文件夹里有1个文档和3张照片 谢谢 后续可能不止100个文档 可能更多
2022年05月30日 03点05分
1
level 9
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起双击运行
<# :
cls&echo off&cd /d "%~dp0"&mode con lines=5000
rem 将当前目录里的多个txt文本文件和图片文件,分别按照指定数量平分/划分到多个文件夹里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "current=%cd%"
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>$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);
$current=$env:current;
$files1=@(dir -literal $current|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
$files2=@(dir -literal $current|?{(@('.jpg','.jpeg','.png','.bmp') -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
if($files1.length -ge 1){
$arr=[ExpDir]::Sort($files1);
$count=3;$n=1;
$newfolder=$n.ToString();
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
for($i=0;$i -lt $arr.count;$i++){
$arr[$i]+$c+$newfolder;
if((($i+1) % $count) -eq 0){
$n++;
$newfolder=$n.ToString();
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
}
}
}
if($files2.length -ge 1){
$arr=[ExpDir]::Sort($files2);
$count=3;$n=1;
$newfolder=$n.ToString();
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
for($i=0;$i -lt $arr.count;$i++){
$arr[$i]+$c+$newfolder;
if((($i+1) % $count) -eq 0){
$n++;
$newfolder=$n.ToString();
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
}
}
}
2022年05月30日 05点05分
3
![[真棒]](/static/emoticons/u771fu68d2.png)
你比我写的好的多 牛逼
2022年05月31日 12点05分