-2

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!!!

0

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.