how set a name of a unknown file in the folder be sth

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kalaam116
Posts: 2
Joined: 12 May 2011 04:43

how set a name of a unknown file in the folder be sth

#1 Post by kalaam116 » 12 May 2011 05:06

Hi,
If a have a folder called "folderA"(in D:\), which consist of few files with name that i don't know
folderA
-unknownfile
-unknownfile
-unknownfile
I want to set the unknownfiles to be variables with a .bat

Code: Select all

cd D:
dir folderA /b>>%TEMP%/temp.ini
set variables1=firstlineoftheini
set variables2=secondlineoftheini
until the end

is it possible? :P

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: how set a name of a unknown file in the folder be sth

#2 Post by !k » 12 May 2011 08:05

Code: Select all

@echo off &setlocal enableextensions enabledelayedexpansion

set "folder=D:\folderA"

set /a cnt=1
for /f "delims=" %%f in ('dir /b /a-d /s /on "%folder%"') do (
set "variables!cnt!=%%f"
set /a cnt+=1
)
set variables

or without enabledelayedexpansion

Code: Select all

@echo off &setlocal enableextensions

set "folder=D:\folderA"

set /a cnt=1
for /f "delims=" %%f in ('dir /b /a-d /s /on "%folder%"') do (
call set "variables%%cnt%%=%%f"
set /a cnt+=1
)
set variables

kalaam116
Posts: 2
Joined: 12 May 2011 04:43

Re: how set a name of a unknown file in the folder be sth

#3 Post by kalaam116 » 12 May 2011 08:19

How can I echo those variables- -?

Code: Select all

echo %variables1%

- -?Thx

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: how set a name of a unknown file in the folder be sth

#4 Post by !k » 12 May 2011 09:05

Code: Select all

@echo off &setlocal enableextensions enabledelayedexpansion

set "folder=D:\folderA"

set /a cnt=1
for /f "delims=" %%f in ('dir /b /a-d /s /on "%folder%"') do (
set "variables!cnt!=%%f"
set /a cnt+=1
)
rem set variables

set /a cnt-=1
for /l %%i in (1,1,%cnt%) do echo "!variables%%i!" is variable # %%i

:?

Post Reply