I'm trying to automate my folder-tree creation, where I request to user the year (that can be more than one), and after that I create folder from 01 to 12 (January to December) inside the year folder. Into of each month's folders, I'd can be create another folders according to my necessity, to mantain organization.
When I run the .bat script in my Windows environment, I receive command syntax error but, reviewed the whole script, and I can't find where is the error. I think that what I'm want to do is not so difficult, therefore I'll put below the whole script imagining that, with basic knowledge of reading and writing scripts, you from community be able to understand that I want to do.
@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions
PUSHD "%~dp0"
set "curpath=%~dp0"
set /p years=Insert a year (in case more than one value, years can be separated by comma.Ex.:2018,2019):
REM For each year that the user insert(separated by comma) the loop for creates a respective folder
for %%G in (%years%) do (
set "srcpath=%curpath%%%G"
mkdir "!srcpath!"
set /a loopcount=12
set /a increment=1
REM Beginning here the loop where will create month folder(01 to 12), inside year folder
:beginloop
if !increment! LSS 10 (
set "fmtinc=0!increment!"
) else (
set "fmtinc=!increment!"
)
mkdir "!srcpath!\!fmtinc!\DCTF"
mkdir "!srcpath!\!fmtinc!\Despesas"
mkdir "!srcpath!\!fmtinc!\DeSTDA"
mkdir "!srcpath!\!fmtinc!\Folha Pagamento"
mkdir "!srcpath!\!fmtinc!\GFIP"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NF Entrada"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NF Entrada\PDF"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NF Entrada\XML"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NF Obra"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NF Saida"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NF Saida\PDF"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NF Saida\XML"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NFS Prestados"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NFS Prestados\PDF"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NFS Prestados\XML"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NFS Tomados"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\NFS Tomados\Outros Municipios"
mkdir "!srcpath!\!fmtinc!\Notas Fiscais\Relatorio Faturamento Mensal"
mkdir "!srcpath!\!fmtinc!\RAIS"
mkdir "!srcpath!\!fmtinc!\GIA"
mkdir "!srcpath!\!fmtinc!\SPED"
mkdir "!srcpath!\!fmtinc!\SPED\EFD ICMS e IPI"
mkdir "!srcpath!\!fmtinc!\SPED\EFD Contribuições"
set /a increment+=1
set /a loopcount-=1
REM While the value of decrement variable loopcount not iquals to 0(zero) the loop continues creating new folder for next month, redirecting program flow of here to :beginloop
if !loopcount! == 0 ( goto exitloop )
goto beginloop
:exitloop
)
PAUSE
In that case, user must put and run the script directly in the folder that he want to create all the new folders. For that, in the beginning is stored the path where script is located in the variable curpath.