我有一个批处理文件,用于为客户创建新的项目文件夹,引导用户完成创建过程,并将适当的文件和文件夹添加到中心位置.我需要添加一个输入部分,以便他们可以输入日期(不总是当前日期),它包含在文件的命名中.
我有这个问题,而且我已经找到了高低,无法找到我的答案,就是我需要虚拟证明日期输入.我希望用户以MM-DD-YYYY格式输入日期,包括破折号.然后需要将其格式化为YYYY-MM-DD.它需要足够智能,以迫使用户使用所需的MM-DD-YYYY格式;必须是数字和短划线,没有斜线,正确数量的字符,等等.
我无法找到任何接近甚至遥远的地方让我到达我需要的地方所以我在那里问那些令人敬畏的天才在这方面的帮助,因为它正在推动我的墙.下面是我的脚本代码.我需要在输入作业类型后立即输入此输入. “请插入日期(MM-DD-YYYY格式):”
@echo off setlocal EnableDelayedExpansion set version=7.95 set projectpath="P:" set workbookpath="\\server2\Documents\Blanks (DO NOT EDIT)\dryingworkbook_v3r75.xls" set questions="\\server2\Documents\Blanks (DO NOT EDIT)\Abatement and Mold Questions.txt" set notes="\\server2\Documents\Blanks (DO NOT EDIT)\Job Notes.docx" set info="\\server2\Documents\Blanks (DO NOT EDIT)\Job Information.docx" set bizname=1 ECHO =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ECHO = Welcome to SERVPRO Project Creation Wizard v%version% = ECHO =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ECHO. :sof ECHO. ECHO Is this new project for a Residential or Commercial job? :loopJobType SET /P jobtype=Enter [r] for Residential or [c] for Commercial: ECHO. IF "%jobtype%" == "r" GOTO :loopResidential IF "%jobtype%" == "R" GOTO :loopResidential IF "%jobtype%" == "c" GOTO :loopCommercial IF "%jobtype%" == "C" GOTO :loopCommercial GOTO :loopJobType :loopResidential ECHO You have chosen to create a new Residential job project. ECHO. set type=1 GOTO :loopFirstName :loopCommercial ECHO You have chosen to create a new Commercial job project. ECHO. set type=2 SET /p bizname=Please enter the business name: ECHO. IF "%bizname%"=="" GOTO :loopCommercial :loopFirstName SET /P FirstName=Please enter the insured's first name: IF "%FirstName%"=="" GOTO :loopFirstName call :format FirstName :loopLastName ECHO. SET /P LastName= Please enter the insured's last name: IF "%LastName%"=="" GOTO :loopLastName call :format LastName SET FullName=%LastName%,%FirstName% SET FullBizName=%bizname% (%FullName%) goto :ConfirmProject :format set Name=!%1! set Head=%Name:~0,1% set Tail=%Name:~1% for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set Head=!Head:%%a=%%a! for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do set Tail=!Tail:%%a=%%a! set %1=%Head%%Tail% GOTO :eof :ConfirmProject ECHO. IF "%type%" == "1" SET /P yesno=Are you sure you want to add "%FullName%" to the Project directory? [y/n] IF "%type%" == "2" SET /P yesno=Are you sure you want to add "%FullBizName%" to the Project directory? [y/n] IF "%yesno%" == "y" GOTO :CreateProject IF "%yesno%" == "Y" GOTO :CreateProject IF "%yesno%" == "n" GOTO :sof IF "%yesno%" == "N" GOTO :sof GOTO :ConfirmProject :CreateProject IF "%type%" == "1" SET ProjectName=%FullName% IF "%type%" == "2" SET ProjectName=%FullBizName% :: Create a folder containing a new project. mkdir "%projectpath%\%ProjectName%" ECHO. ECHO. ECHO Creating a Project directory for "%ProjectName%" ... :: Create a folder within said project that will contain job documents. ECHO Creating a Documents directory for "%ProjectName%" ... mkdir "%projectpath%\%ProjectName%\Documents" :: (Taken out of use 7-15-13) ECHO Adding a Job Information file for "%ProjectName%" ... :: (Taken out of use 7-15-13) copy /-Y %info% "%projectpath%\%ProjectName%\Documents\Job Information - %ProjectName%.docx" ECHO Documents directory creation for "%ProjectName%" finished ... :: Create a folder within said project that will contain drying workbook(s). ECHO Creating a Drying Workbook directory for "%ProjectName%" ... mkdir "%projectpath%\%ProjectName%\Drying Workbooks" :: Copy a new blank workbook to the project workbook directory and give it the proper name. ECHO Adding a Drying Workbook for "%ProjectName%" ... copy /-Y %workbookpath% "%projectpath%\%ProjectName%\Drying Workbooks\DRY 1_%ProjectName%.xls" ECHO Adding an Abatement and Mold Questions file for "%ProjectName%" ... copy /-Y %questions% "%projectpath%\%ProjectName%\Drying Workbooks\Abatement and Mold Questions.txt" ECHO Drying Workbook directory creation for "%ProjectName%" finished ... :: Create a folder within said project that will contain original photos. ECHO Creating a Photos directory for "%ProjectName%" ... mkdir "%projectpath%\%ProjectName%\"Photos :: Create a folder within said project photo folder that will contain resized photos. mkdir "%projectpath%\%ProjectName%\Photos\Resized" mkdir "%projectpath%\%ProjectName%\Photos\Upload" ECHO Photos directory creation for "%ProjectName%" finished ... :: Add in Job Notes file. ECHO Adding a Job Notes files for "%ProjectName%" ... copy /-Y %notes% "%projectpath%\%ProjectName%\Job Notes - %ProjectName%.docx" :: Log the creation of the project. FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c) echo off > "%projectpath%\Logs\%ProjectName% - [Project Created %date% by %computername%].txt" ECHO Logging "%ProjectName%" creation date and time... ECHO Project directory creation for "%ProjectName%" finished ... GOTO :OpenProject :OpenProject :: Ask if the project should be opened now. If so open and close script,else close script. set /p reply=Do you want to open the "%ProjectName%" project now? [y/n] if "%reply%" == "y" %SystemRoot%\explorer.exe "%projectpath%\%ProjectName%" IF "%yesno%" == "Y" %SystemRoot%\explorer.exe "%projectpath%\%ProjectName%" GOTO :eof IF "%yesno%" == "n" GOTO :No IF "%yesno%" == "N" GOTO :No exit :No ECHO. ECHO. ECHO You have successfully created a new project for %ProjectName%. ECHO. ECHO Press any key to exit . . . PAUSE>NUL :eof
下面的批处理文件检查插入的日期是否具有正确的格式,并且它代表一个有效的日期,即每月有正确的天数,即使是闰年的二月!
@echo off setlocal EnableDelayedExpansion set i=0 for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do ( set /A i+=1 set dpm[!i!]=%%a ) set /P "inDate=Please insert date (MM-DD-YYYY format): " if "%inDate:~2,1%%inDate:~5,1%" neq "--" goto invalidDate for /F "tokens=1-3 delims=-" %%a in ("%inDate%") do set "MM=%%a" & set "DD=%%b" & set "YYYY=%%c" ver > NUL set /A month=1%MM%-100,day=1%DD%-100,year=1%YYYY%-10000,leap=year%%4 2>NUL if errorlevel 1 goto invalidDate if not defined dpm[%month%] goto invalidDate if %leap% equ 0 set dpm[2]=29 if %day% gtr !dpm[%month%]! goto invalidDate if %day% lss 1 goto invalidDate echo Date correct: %YYYY%-%MM%-%DD% goto :EOF :invalidDate echo Bad date