A bit embarrased that my first question is about a simple batch file, but my knowledge is quite limited in this topic.
I am writing a simple batch script to copy some data from a to b. For this reason i want to create destination folders according to the current month and check if the folder already exists.
I am not able to identify why my code exits at line 14 without throwing anything after pressing a key. I also tried verifying the code with a batch code verifying tool (BatCodeCheck "quite outdated"). However it throws no errors or warnings regarding my problem.
The code in question:
@echo off
echo Getting current month...
set month=%date:~3,2%
if %month:~0,1% == 0 (
set /A month=%month:~1,2%-1
) ELSE (
set /A month=%month%-1
)
if [%month:~1,2%] == [] (
set month=0%month%
)
echo "%month% is the month before"
echo Checking for monthly folder...
pause
if exist %~dp0%month%\ (
echo "Folder already exists. Press y to overwrite"
pause
set /p Input=Overwrite? (y/n):
if /I "%Input%"NEQ"y" (
EXIT 0
)
) ELSE (
echo "Folder doesn't exist already. Creating..."
mkdir %~dp0%month%\
)
The check log:
Time : 2022-05-12 19:10:08
Program : BatCodeCheck, Version 0.38
Arguments : D:\RunBackup.bat /L /W
File name : "D:\RunBackup.bat"
File date : 2022-05-12 19:10:02
File encoding : ASCII
Tests : ABELMSUV
A = command line Arguments for batch commands
B = Best practice tips
E = Environment variables
L = Labels
M = common Mistakes
S = verbose Summary (variables, labels, subroutines)
U = Undefined environment variables
V = Vulnerabilities
RISKY CODE:
Line 18: SET /P could make your code vulnerable to exploits (see http://www.robvanderwoude.com/battech_inputvalidation.php#SetP)
SUMMARY:
1 line generated a warning and should be examined
Note that some warnings are only displayed once. Correct the errors and run this test again.
Hopefully its not a syntax error i am missing...