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!!!
Asked
Active
Viewed 103 times
1 Answers
1
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

Happy Face
- 1,061
- 7
- 18
-
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](http://stackoverflow.com/questions/10544646/dir-output-into-bat-array/10569981#10569981) and enclose the index in square braquets: `set "weapon[!count!]=%%~na"` – Aacini Oct 10 '15 at 14:41