Implementing code for creating a folder with DOS batches _dos/bat

Source: Internet
Author: User
Tags goto modulus
Topic: Create a folder with DOS batch implementation
Requirements: 1 require the creation of a file name format "YYYY1-MM1-DD1 to Yyyy2-mm2-dd2" folder
2 of which YYYY1-MM1-DD1 is today's date; YYYY2-MM2-DD2 is four days after the date
Answer:
Copy Code code as follows:

@echo off
REM comparison operator: EQU-equals neq-not equal to LSS-less than leq-less than or equal to GTR-greater than GEQ-greater than or equal to
REM modulus operator:% dos modulus operator (percent% in batch file, not batch command line%)

REM Log folder name initial value
Set filelog=%date:~0,10% to
REM Subsequent date of the variable
set/a y=0
set/a m=0
set/a d=0
The DD two-bit in rem fetch date YYYYMMDD
set/a dd=%date:~8,2%
set/a ddp4=%dd% + 4
REM Take date yyyymmdd mm two bits
set/a mm=%date:~5,2%
set/a mmp1=%mm% + 1
REM Fetch date YYYYMMDD yyyy four bits
set/a yyyy=%date:~0,4%
set/a yyyyp1=%yyyy% + 1
set/a yymd=yyyy% 4

REM If it's a 31-day month (1,3,5,7,8,10,12)
REM December Special
If%mm% equ 12 (
If%ddp4% Leq 31 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 31 (
If%mmp1% GTR 12 (
set/a y=%yyyy% + 1
set/a m= 1
set/a d=%ddp4%-31
)
)
Goto END
)
If%mm% equ 10 (
If%ddp4% Leq 31 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 31 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-31
)
Goto END
)
If%mm% equ 8 (
If%ddp4% Leq 31 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 31 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-31
)
Goto END
)
If%mm% equ 7 (
If%ddp4% Leq 31 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 31 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-31
)
Goto END
)
If%mm% equ 5 (
If%ddp4% Leq 31 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 31 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-31
)
Goto END
)
If%mm% equ 3 (
If%ddp4% Leq 31 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 31 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-31
)
Goto END
)
If%mm% equ 1 (
If%ddp4% Leq 31 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 31 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-31
)
Goto END
)

REM If it's a 30-day month (4,6,9,11)
If%mm% equ 11 (
If%ddp4% Leq 30 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 30 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-30
)
Goto END
)
If%mm% equ 9 (
If%ddp4% Leq 30 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 30 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-30
)
Goto END
)
If%mm% equ 6 (
If%ddp4% Leq 30 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 30 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-30
)
Goto END
)
If%mm% equ 4 (
If%ddp4% Leq 30 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 30 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-30
)
Goto END
)

rem if it is 28 or 29 days of the month (2)
If%mm% equ 2 (
If%yymd% equ 0 (
If%ddp4% Leq 29 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 29 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-29
)
Goto END
)
If%ddp4% Leq 28 (
set/a y=%yyyy%
set/a m=%mm%
set/a d=%ddp4%
)
If%ddp4% GTR 28 (
set/a y=%yyyy%
set/a m=%mmp1%
set/a d=%ddp4%-28
)

)

REM Combination folder name and create a folder
: End
If%m% LSS set filelog=%filelog%%y%-0%m%
If not%m% LSS set filelog=%filelog%%y%-%m%
If%d% LSS set filelog=%filelog%-0%d%
If not%d% LSS set filelog=%filelog%-%d%
mkdir%filelog%

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.