萌新求助大佬 遍历目录下的最后三个子文件夹
bat吧
全部回复
仅看楼主
level 1
求助@璐村惂鐢ㄦ埛_000076K馃惥 off&setlocal enabledelayedexpansionset
"folder=D:\gallery/00/%date:~0,4%%date:~5,2%%date:~8,2%"
set /a n=0
(for /d %%a in ("%folder%\*") do (
set /a n+=1
set fname = %%a;
echo %%a
)
set /a m = !n!-1set /a k = !m!-1
)
//目录下最后三个文件夹,最好放到一个数组里,然后循环数组 => dosomething
2021年10月14日 06点10分 1
level 9
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
<# :
cls&echo off
rem 获取一个指定目录里的最后三个文件夹
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$folder="D:\gallery\00\"+(get-date).toString('yyyyMMdd');
if(-not (test-path -liter $folder)){write-host ('"'+$folder+'" 未找到');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;
$folders=@(dir -liter $folder|?{$_ -is [System.IO.DirectoryInfo]}|%{$_.Name});
if($folders.length -ge 1){
$arr=[ExpDir]::Sort($folders);
$last=$arr.Count-3;
if($last-le 0){$last=0;}
for($i=$arr.Count-1;$i -ge $last;$i--){$folder+'\'+$arr[$i];}
}
2021年10月15日 05点10分 3
1