- @echo off
- setlocal enabledelayedexpansion
-
- :: 提示用户输入月份
- echo 请输入月份数字(1-12):
- set /p month_input=
-
- :: 检查输入是否合法
- if not defined month_input (
- echo 请输入有效的月份数字(1-12)!
- exit /b
- )
-
- if !month_input! lss 1 (
- echo 请输入有效的月份数字(1-12)!
- exit /b
- )
-
- if !month_input! gtr 12 (
- echo 请输入有效的月份数字(1-12)!
- exit /b
- )
-
-
- :: 设置月份变量
- set month_num=!month_input!
- set month_str=!month_num!
-
-
- :: 如果月份小于 10,则前面加 0
- if !month_num! lss 10 (
- set month_str=0!month_num!
- )
-
-
- :: 获取当前年份
- for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value') do (
- set datetime=%%a
- )
- set year=%datetime:~0,4%
-
-
- :: 判断是否为闰年
- set is_leap_year=0
- if !year! %% 400 equ 0 (
- set is_leap_year=1
- ) else if !year! %% 100 neq 0 (
- if !year! %% 4 equ 0 (
- set is_leap_year=1
- )
- )
-
- pause
- :: 根据用户输入的月份创建对应的目录
- set main_dir=!year!年!month_str!月
- md "!main_dir!" >nul 2>nul
-
- pause
- :: 根据月份创建子目录
- if !month_num! equ 2 (
- if !is_leap_year! equ 1 (
- for /l %%d in (1,1,29) do (
- set day=%%d
- if %%d lss 10 set day=0%%d
- md "!main_dir!\%%day%日" >nul 2>nul
- )
- ) else (
- for /l %%d in (1,1,28) do (
- set day=%%d
- if %%d lss 10 set day=0%%d
- md "!main_dir!\%%day%日" >nul 2>nul
- )
- )
- ) else if !month_num! equ 4 (
- for /l %%d in (1,1,30) do (
- set day=%%d
- if %%d lss 10 set day=0%%d
- md "!main_dir!\%%day%日" >nul 2>nul
- )
- ) else if !month_num! equ 6 (
- for /l %%d in (1,1,30) do (
- set day=%%d
- if %%d lss 10 set day=0%%d
- md "!main_dir!\%%day%日" >nul 2>nul
- )
- ) else if !month_num! equ 9 (
- for /l %%d in (1,1,30) do (
- set day=%%d
- if %%d lss 10 set day=0%%d
- md "!main_dir!\%%day%日" >nul 2>nul
- )
- ) else if !month_num! equ 11 (
- for /l %%d in (1,1,30) do (
- set day=%%d
- if %%d lss 10 set day=0%%d
- md "!main_dir!\%%day%日" >nul 2>nul
- )
- ) else (
- for /l %%d in (1,1,31) do (
- set day=%%d
- if %%d lss 10 set day=0%%d
- md "!main_dir!\%%day%日" >nul 2>nul
- )
- )
-
- echo Folder created.
-
- :: 复制文件到对应月份的目录
- copy "%CD%\1.xlsx" "!main_dir!\\" >nul 2>nul
-
- exit /b
复制代码 无法运行,提示:
请输入月份数字(1-12):
1
此时不应有 %。 |