每个文件夹中有N多张图片,我现在想提取里面的前两张图片,和最
bat吧
全部回复
仅看楼主
level 2
每个文件夹中有N多张图片,我现在想提取里面的前两张图片,和最后一张。求大佬解答 在线等
2020年05月20日 08点05分 1
level 2

2020年05月20日 08点05分 2
level 8
@璐村惂鐢ㄦ埛_000076K馃惥 off&title 提取指定文件夹中的前两张与最后一张图片
setlocal EnableDelayedExpansion
set lines=0
set "Path_d=%~dp0\test"
for /f "delims=" %%i in ('dir /a /b %Path_d%') do (
set /a lines+=1
if !lines! equ 1 echo;%%i
if !lines! equ 2 echo;%%i
)
for /f "delims=" %%i in ('dir /a /b /o-d %Path_d%') do (
echo;%%i
pause >nul&exit
)
自己测试过的,没问题
2020年05月20日 12点05分 3
@金坷垃ooo 感谢 大佬
2020年05月27日 00点05分
为什么运行就闪退了?
2022年11月26日 10点11分
提取出来的图片放在哪了呀?
2022年11月26日 10点11分
level 8
提一下,我这里是默认时间排序的,所以用的是/o-d,如果你是其他排序就对应一下参数
2020年05月20日 12点05分 4
level 9
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI/GB2312,跟要处理的多个文件夹放一起双击运行
<# :
cls&echo off&cd /d "%~dp0"&mode con lines=5000
rem 从当前目录下多个子文件夹里提取出前后几张图片
set #=Any questions&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "self=%~f0"
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$ext=@('.jpg','.jpeg','.bmp','.png');
$num=@(1,2,-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;
$b=[Convert]::FromBase64String("IC0tPiA=");
$c=[Text.Encoding]::Default.GetString($b);
$self=get-item -literal $env:self;
$current=$self.Directory.FullName.trimend('\');
$newfolder=$current+'\#result';
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
$folders=@(dir -liter $current|?{($_.FullName -ne $newfolder) -and ($_ -is [System.IO.DirectoryInfo])});
for($i=0;$i -lt $folders.length;$i++){
$files=@(dir -liter $folders[$i].FullName|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
if($files.length -ge 1){
$dic=New-Object 'System.Collections.Generic.Dictionary[string,string]';
$arr=[ExpDir]::Sort($files);
for($j=0;$j -lt $num.length;$j++){
$n=$num[$j];
if($n -gt 0){$n=$num[$j]-1};
if($arr[$n] -ne $null){
$srcfile=$folders[$i].FullName+'\'+$arr[$n];
if(-not $dic.ContainsKey($srcfile)){
$dic.add($srcfile,'');
$srcfile.Substring($current.length)+$c+$newfolder.Substring($current.length);
}
}
}
}
}
2022年11月29日 10点11分 6
1