There is a folder called 'weapons', and in this folder are empty files, like 'P250.wep, AWP.wep'. I need to make a batch file that loops through the folder, takes every file name, and puts it in a different variable. For example, after looping these files, P250.wep should be stored in variable weapon1, and AWP.wep in weapon2. Please help me!!!
1 Answer
You can try this method, but it's automatically sort alphabetically before the loop starts. So, this mean AWP.wep will be weapon1, and P250.wep will be weapon2. One more thing, I don't know which one do you want to store, you mentioned "take every file name", but you also mentioned file name with extension... If you don't mind, take a look at the script:
@echo off
Setlocal EnableDelayedExpansion
set count=1
for %%a in (c:\PATH\weapons) do (
set "weapon!count!=%%~na"
set /a count+=1
)
pause >nul
1 Comment
Aacini
I suggest you to start with
set count=0 and do set /a count+=1 before the set of the element; this way the count variable have the number of elements at end. Also, I suggest you to use the standard array notation and enclose the index in square braquets: set "weapon[!count!]=%%~na"