求助大神获取最新文件名的方法
bat吧
全部回复
仅看楼主
level 3
有一个文件夹下面有20个子文件夹,里面不定时的生存新的文件,我需要做个bat可以实时监控每个文件夹的最新文件名,多谢大神
2021年08月19日 00点08分 1
level 3
大神来啊
2021年08月19日 01点08分 2
level 3
有人吗
2021年08月19日 02点08分 3
level 3
还是没有人
2021年08月19日 04点08分 4
level 9
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
<# :
cls&echo off
rem 监测一个指定文件夹里新生成/新创建的文件
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
cd /d "%~dp0"
set "folder=D:\xxx\某文件夹"
if not exist "%folder%" (echo;"%folder%" 未找到&pause&exit)
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$folder=get-item -liter $env:folder;
$watcher=New-Object System.IO.FileSystemWatcher;
$watcher.Path=$folder.FullName;
$watcher.Filter='*.*';
$watcher.IncludeSubdirectories=$true;
write-host 'monitoring……';
while(1){
$change=$watcher.WaitForChanged('Created', 500);
if($change.TimedOut -eq $false){
foreach($c in $change){
$newfile=$folder.FullName+'\'+$c.Name;
if([IO.File]::Exists($newfile)){write-host $c.Name;}
}
}
}
2021年08月19日 07点08分 5
level 1
echo off
for /r %%i in (*.*) do (
set %%~si=1
)
:loop
for /r %%i in (*.*) do (
if not defined %%~si echo;新文件:%%i
if not defined %%~si set %%~si=1
)
pause
echo;-------------------------------------------
goto :loop
2021年08月19日 07点08分 6
1