文件夹内有若干图片,每4个提取放在一个文件夹
bat吧
全部回复
仅看楼主
level 4
文件夹内有若干图片,按这些图片排列的先后顺序每4个提取放在一个文件夹,文件夹以1开始递增的顺序命名,如何实现啊
2021年05月14日 15点05分 1
level 9
不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起双击运行
<# :
cls&echo off&mode con lines=5000
rem 对当前目录下的图片文件按照指定数量平分/平均分配到多个子文件夹里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312')))) -Args '%~f0'"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$count=4;
$ext=@('.jpg','.jpeg','.bmp','.png');
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$begin=1;
$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;
$files=@(dir -liter $path|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
if($files.length -ge 1){
$arr=[ExpDir]::Sort($files);
for($i=0;$i -lt $arr.count;$i++){
$newfolder=$path+'\'+$begin.toString();
if(-not (test-path -liter $newfolder)){
[void](md $newfolder);
};
write-host ($arr[$i]+' --> '+$begin.toString());
if((($i+1) % $count) -eq 0){$begin++;};
};
}
2021年05月14日 17点05分 2
level 1
echo off&setlocal enabledelayedexpansion
set a=0
set c=1
for %%i in (g:\*.bmp) do (
set/a a="!a!+1"
if !a! gtr 4 (set a=0 && set/a c="!c!+1") else (xcopy %%~dpnxsi %%~dp!c!)
)
pause
2021年06月18日 15点06分 4
谢谢
2021年06月19日 12点06分
level 1
有错误改一下
echo off&setlocal enabledelayedexpansion
set a=0
set c=1
for %%i in (d:\*.bmp) do (
set/a a="!a!+1"
if !a! equ 4 (xcopy %%~dpnxsi %%~dpi!c! & set a=0 && set/a c="!c!+1") else (xcopy %%~dpnxsi %%~dpi!c!)
)
pause
2021年06月19日 15点06分 5
谢谢
2021年06月19日 15点06分
1