Batch file folder echo with out using dir

January 10, 2011 at 20:57:44
Specs: Windows 7 Ultimate, 4.17Ghz 8GB ram
Is there a way for a batch file to search a folder then echo out the names of the containing files or folders. not using the dir command because I want to use the names as a variable.

See More: Batch file folder echo with out using dir

Report •


#1
January 10, 2011 at 21:59:41
"not using the dir command because I want to use the names as a variable"

Not at all clear.

Might help to say what you *DO* want to do.


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
January 10, 2011 at 23:19:19
Hello everyone,

I am new at batch coding. I believe I am trying to do the same as rocky3598. let me explain.

I want to get all the folder and subfolder of a directory (full path), set the as VAR in strings and parse them to get the parts i need.

I have this at the moment

@echo off
set count=1
for /f %%a in ('dir /s /on /b /ad') do (call :sdosums %%a)
goto :eof

:sdosums
echo str%count%=%1
set /a count+=1
pause
goto :eof

It does echo what i want but I do not know how to create a workable string from it

Thanks


Report •

#3
January 11, 2011 at 04:34:38
A simpler version of fabio.geraci is:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET Num=1
FOR /f "tokens=*" %%a IN ('dir /s /on /b /ad') DO (
SET Var!Num!=%%a
SET /a Num+=1
)

You will then be able to access the variable through %Var1%, %Var2, Var3% etc.

Can I put a question here?


Report •

Related Solutions

#4
January 11, 2011 at 10:54:39
Matt123,

Thanks.


Report •

#5
January 11, 2011 at 11:30:55
Thats exactly what I wanted to do. But is there any way to get it to work in a different directory? Can i have it point somewhere else?

Would this work?
cd e:\somefolder\xyx\j\
SET Num=1
FOR /f "tokens=*" %%a IN ('dir /s /on /b /ad') DO (
SET Var!Num!=%%a
SET /a Num+=1
)

Would that make it list the folders in the j folder?


Report •

#6
January 11, 2011 at 12:53:24
Did you try it? =)

It should. Just make sure you have delayed expansion enabled (SETLOCAL EnableDelayedExpansion).

Can I put a question here?


Report •

#7
January 11, 2011 at 18:19:46
No I did not try it. I was going to see if you had any other input on it. And i will later tonight when i get back from work.

Report •

Ask Question