Get creation date and time of a folder in batch script

☆樱花仙子☆ 提交于 2019-11-29 16:56:57
@ECHO OFF
SETLOCAL
set "path_of_folder=C:\sql2016\mssql13.sqlexpress03"

if exist "%path_of_folder%" ( 
  echo Path exists.
  for /f "skip=5 tokens=1,2,4 delims= " %%a in (
   'dir /ad /tc "%path_of_folder%\."') do IF "%%c"=="." (
    set "dt=%%a"
    echo Created on: %%a, %%b
  )
) else ( 
  echo Path does not exist. 
)

GOTO :EOF

I used a different target directory and since I run from the prompt, I've replaced the pause.

Note that the variable containing the path now has no closing \, nor is it quoted. This facilitates making modifications, but means that where required, references to that variable need to be "quoted".

Simply pick up the name part of the directory in %%c. Therefore you need a listing of directories hence /ad. The directoryname of interest is . so only execute the assignment and report if the directoryname found is "."

The skip=5 is redundant and can be removed if you prefer. the if filter ensures that the . directory is reported.

Check dirtimejs.bat - it can print dir times independent from control panel settings:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set "path_of_folder=C:\folderA\folderB"

for /f "tokens=1* delims=:" %%a in ('dirtimejs.bat "%path_of_folder%" ^| find "Created :"') do (
     echo %%a
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!