@ECHO OFF
CD C:/Users/Emblemat/Desktop/test_batch/
SET file_f[0]="one"
SET file_f[1]="two"
SET file_f[2]="three"
SET file_f[3]="four"
SET file_f[4]="five"
SET file_f[5]="six"
SET file_f[6]="seven"
SET file_f[7]="eight"
SET extension_to_file_f=".txt"
SET dir_d[0]="according13/"
SET dir_d[1]="according14/"
SET dir_d[2]="according15/"
SET dir_d[3]="according17/"
SET dir_d[4]="according18/"
SET dir_d[5]="according19/"
SET dir_d[6]="according20/"
SET dir_d[7]="according21/"
SET dir_d[8]="according22/"
SET dir_d[9]="according23/"
SET counter=0
:label1
IF NOT DEFINED dir_d[%counter%] GOTO label2 ELSE (
SET /A counter=%counter%+1
ECHO %counter%
GOTO label1
)
:label2
rem GOTO label3
SET /A length_of_dir_d=%counter%-1
SETLOCAL EnableDelayedExpansion
FOR /L %%i IN (0,1,%length_of_dir_d%) DO (
FOR /F "USEBACKQ" %%F IN (`CALL ECHO %%dir_d[%%i]%%`) DO SET temp111=%%F
IF EXIST !temp111! (
ECHO "exists this file"
) ELSE (
ECHO "not exists this file"
IF DEFINED file_f[%%i] (
MD !temp111!
CD !temp111!
FOR /F "USEBACKQ" %%F IN (`CALL ECHO %%file_f[%%i]%%`) DO SET temp112=%%F
TYPE NUL > !temp112!%extension_to_file_f%
ECHO "%CD%"
CD ..
ECHO "%CD%"
ECHO "created dir and file"
) else (
ECHO "not execute not defined"
)
)
)
ENDLOCAL
rem :label3
PAUSE
Jeśli folderów jest np. 5, a plików 3, czy coś w tym stylu (plików mniej niż folderów), to wtedy skrypt utworzy tylko 3 foldery i 3 pliki, ponieważ 5-3=2 foldery nie zostały zdefiniowane.
SO superuser SO superuser SO SO