0

I'm trying to look through files that start with a number and setting it as 2 different variables what I have below works mostly besides for the last part, trying to set %file!num!%

for /R %logs% %%F IN (%S%*.txt) DO (
    for /f "tokens=10 delims=\" %%N IN ("%%F") DO (
    set /a "num+=1"
    echo !num!. %%N
    set "file!num!=%%F"
    )
)

%%F is the full file path for the file

%%N is just the file name

I want to set the file path %%F to %file!num!% to set it as file2 or w/e number it is

Piriwn1
  • 31
  • 3
  • Does this answer your question? [Variables are not behaving as expected](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected) – T3RR0R Mar 01 '20 at 03:08
  • You don't need the other `FOR` command to just get the file name. Read the help for the `FOR` command. There are special `FOR` variable modifiers to parse the file path and file name. Other than that, as long as you have delayed expansion enabled the code should work. – Squashman Mar 01 '20 at 03:40

1 Answers1

0

I took your code examples from your other question and combined it with your code from this question.

I believe this is what you are attempting to do.

@ECHO OFF
setlocal enabledelayedexpansion
SET "S=Foobar"
SET "num=0"
SET "logs=C:\some path"
for /R "%logs%" %%F IN (%S%*.txt) DO (
    set /a "num+=1"
    echo !num!. %%~nxF
    set "file!num!=%%F"
)

set "choice="
set /p choice="Select File Number, or no to exit: "

if /I "%choice%"=="no" (
    goto cleanup
) else (
    start "" "!file%choice%!"
    pause
)

:cleanup
Squashman
  • 13,649
  • 5
  • 27
  • 36