2016-06-27 75 views
0

有什麼方法可以獲取在指定路徑中創建的最新文件夾名稱?在Windows命令提示符下獲取最新創建的文件夾路徑

我有以下路徑:

C:\Test_bat\Archive 

在此路徑文件夾是動態創建和運行我想在此文件夾在某個點重新命名它獲取創建的文件之一。

C:\Test_bat\Archive\NewFolder 

僞我跑步蝙蝠的代碼,test.bat的:

set datestr= %date:~4,2%%date:~7,2%%date:~10,4% 
set currtime=%time: =0% 
set timestr=%currtime:~0,2%%currtime:~3,2%%currtime:~6,2% 
set currdatetime=%datestr%_%timestr% 
rename "C:\Test_bat\Archive\NewFolder\log.txt" "Log_%currdatetime%.txt" 

回答

1

這裏我得到了什麼,花了refrence從下面SO問題:

GetNameOfRecentDirectory

礦執行:

set datestr= %date:~4,2%%date:~7,2%%date:~10,4% 
set currtime=%time: =0% 
set timestr=%currtime:~0,2%%currtime:~3,2%%currtime:~6,2% 
set currdatetime=%datestr%_%timestr% 

FOR /F "delims=" %%i IN ('dir "C:\Test_bat\Archive" /b /ad-h /t:c /o-d') DO (
SET a=%%i 
GOTO :found 
) 
goto :eof 
:found 
rename "C:\Test_bat\Archive\%a%\ExecutionLog.txt" "Log_%currdatetime%.txt" 
相關問題