BAT automatically creates folders (named at the current time)

Source: Internet
Author: User
Tags eol

See the current date and time in cmd first:

@echo offcolor 0aset dt=%datepercenttime%echo %dt%
Pause

1. Use interception to name (time is 12 hours when the name will appear blank, not rigorous)

%date:~0,4%: Represents a 0-bit offset from the left-to-right pointer and then intercepts 4 characters from the position of the offset. If you are intercepting from right to left, you need to add a minus sign
@echo Offcolor 0aset ymd=%Date:~0,4%%Date:~5,2%%Date:~8,2%set HMS=% Time:~0,2%% Time:~3,2%% Time:~6,2%% Time:~9,2%REM or set HMS=% Time:~- One,2%% Time:~-8,2%% Time:~-5,2%% Time:~-2,2%Set DT=%ymd%%hms%Echo%dt%mkdir "%dt%"Pause

2. Use for/f to name (the same effect is achieved using a different notation)

eol=/refers to the behavior that begins with the/number as a comment line
Tokens=x,y,m-n refers to which symbol of each line is passed to the for itself of each iteration, and M-n is the format that refers to a range
Delims=xx refers to the delimiter set. This replaces the space and the default delimiter set for the jump bar.

1. Writing a @echo Offcolor 0a for/F"tokens=1,2 eol=/delims=/"%%ainch('date/t') DoSet yyyy=%%a for/F"tokens=1,2 eol=/delims=/"%%ainch('date/t') DoSet mm=%%b for/F"tokens=2,3 delims=/"%%ainch('date/t') DoSetDD=%%bset Ymd=%yyyy%%mm%%DD%Set Tmp_hms=% Time:~- One,2%% Time:~-8,2%% Time:~-5,2%set HMS=%TMP_HMS: =%6Set DT=%ymd%%hms%Echo%dt%mkdir "%dt%"Pause2. Notation two REM for/F"tokens=1-3 delims=/"%%iinch('date/t') Do Echo%%i%%j%%K is equivalent to the following notation @echo Offcolor 0a for/F"tokens=1,2 delims=/"%%iinch('date/t') DoSet yyyy=%%I for/F"tokens=2 delims=/"%%jinch('date/t') DoSet mm=%%J for/F"tokens=3 delims=/"%%kinch('date/t') DoSetDD=%%KsetDate=%yyyy%%mm%%DD%Set Tmp_time=% Time:~- One,2%% Time:~-8,2%% Time:~-5,2%Set Time=%tmp_time: =%6Set D=%Date%% Time%Echo%d%Pause

When the time is 12-hour system, the above several writing will be a space phenomenon, the following will be shown.

You can add a sentence to your previous script.if "%time:~0,1%"==" "Set"time=0%time:~1%"@echo Offcolor 0a for/F"tokens=*"%%ainch('time/t') DoSet now=%%aset Ymd=%Date:~0,4%%Date:~5,2%%Date:~8,2%set HMS=%now:~0,2%%now:~3%% Time:~6,2%Set DT=%ymd%%hms%Echo%dt%Pause

BAT automatically creates folders (named at the current time)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.