简体   繁体   中英

Browse the date folder windows batch script

I want to browse the date wise folder in a script. The folders are created daily as per sys date like 20111221, 20111031 etc. My problem is I am not able to browse the folder from script, it is showing path error.

I am trying to browse D:\\Sites\\Sum\\%DATE:~-4%%DATE:~4,2%%DATE:~7,2%\\

Pls help

Probably it is a problem with the date format. %DATE% returns the current date using the short date format, that is fully (endlessly) customizable. One user may configure its system to return Fri040811, and another user may choose 08/04/2011...it's a complete nightmare for a BAT programmer.

A possible solution is to use WMIC. WMIC Path Win32_LocalTime Get Day,Hour,Minute,Month,Second,Year /Format:table returns the date in a convenient way to directly parse it with a FOR.

@ECHO OFF
FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
   SET FD=%%F%%D%%A
)
ECHO D:\SITES\SUM\%FD%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM