Reputation: 5784
Is there a way to get the creation date of a folder in pure batch file (no power script)? In particular, I would like to get it inside this for loop:
FOR /f "tokens=*" %%G in ('dir /b /s /a:d "C:\asdf\*"') DO CALL :loopbody "%%~tG" "%%G"
This loop call a 'function' with the modification date of the folder as the first parameter and the path of the folder as the second parameter.
Upvotes: 3
Views: 13676
Reputation: 57252
for /f "skip=5 tokens=1,2 delims= " %%A in ('dir /ad /od /tc "dirname"') do (
echo %%A-%%B
goto :end_loop
)
:end_loop
Try this.Result will depend on your time settings and probably you'll need to tune the tokens and delims.It's possible also with WMIC
and hybrid jscript/vbscript ,but will need a few minutes to create a script.
EDIT with wmic:
WMIC path Win32_Directory WHERE name='C:\\SomeDir' get creationdate
EDIT Here are some ready to use scripts using different methods to acquire file or directory time stamps :
Upvotes: 7
Reputation: 37569
@ECHO OFF &SETLOCAL
CD "StartFolder"
FOR /D /R %%G in (*) DO (
SET "FileName=%%~G"
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F %%H IN ('wmic fsdir where name^="!FileName:\=\\!" get creationdate^|find "."') DO SET "cdate=%%H"
CALL :loopbody "!cdate:~6,2!/!cdate:~4,2!/!cdate:~0,4!-!cdate:~8,2!:!cdate:~10,2!:!cdate:~12,2!" "!FileName!"
ENDLOCAL
)
GOTO:EOF
:loopbody
ECHO %~1 "%~2"
EXIT /B
Upvotes: 4