Page 1 of 1

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

Posted: 12 May 2011 05:06
by kalaam116
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

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

Posted: 12 May 2011 08:05
by !k

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

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

Posted: 12 May 2011 08:19
by kalaam116
How can I echo those variables- -?

Code: Select all

echo %variables1%

- -?Thx

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

Posted: 12 May 2011 09:05
by !k

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

:?