Set list of sobfolder as string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
fabio.geraci
Posts: 4
Joined: 11 Jan 2011 02:20

Set list of sobfolder as string

#1 Post by fabio.geraci » 11 Jan 2011 02:37

Hello everyone,

I am new at batch coding. 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

Code: Select all

@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

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

Re: Set list of sobfolder as string

#2 Post by !k » 11 Jan 2011 03:20

Code: Select all

@echo off
setlocal enableextensions
cd.>str.txt
for /f %%a in ('dir /s /on /b /ad') do (call :sdosums %%a)
set /p str=<str.txt
del str.txt /q
set str
pause
goto :eof

:sdosums
  <nul set /p str=%1;%str%>>str.txt
goto :eof

fabio.geraci
Posts: 4
Joined: 11 Jan 2011 02:20

Re: Set list of sobfolder as string

#3 Post by fabio.geraci » 11 Jan 2011 04:53

Thanks,

as I said am new where can I manipulate the str created

cheers

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Set list of sobfolder as string

#4 Post by aGerman » 11 Jan 2011 11:30

If you have a lot of folders you will get an overflow of variable str. IMHO not a good idea to work with a "string". Maybe you could "manipulate" the pathes on the fly. Depends on what you meant if you said you would like to "manipulate" something.

Regards
aGerman

fabio.geraci
Posts: 4
Joined: 11 Jan 2011 02:20

Re: Set list of sobfolder as string

#5 Post by fabio.geraci » 11 Jan 2011 13:05

I need to separate with "/" and rebuild a paths over a remote server so that is way I was looking to get something on the line:

str1=c:/blabla/test1
str2=c:/blabla/test2
str3=c:/blabla/test3

then from there rebuild as:

i/caf/test1
i/caf/test2
i/caf/test3

I do understand that for instance with python i would have a better choice, but not everybody has a python at the office.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Set list of sobfolder as string

#6 Post by avery_larry » 11 Jan 2011 13:11

but not everybody has a python at the office.

So true, so true.


:lol:

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Set list of sobfolder as string

#7 Post by aGerman » 11 Jan 2011 15:22

Hmm. It seems you want to replace a substring of the path and convert the Windows path (back slashes) to an Unix path (slashes).

The whole thing on the fly:

Code: Select all

@echo off &setlocal
set "OldStr=C:\blabla"
set "NewStr=i/caf"


for /f "delims=" %%a in ('dir /s /on /b /ad') do (
  set "str=%%~a"
  setlocal enabledelayedexpansion
  set "str=!str:%OldStr%=%NewStr%!"
  set "str=!str:\=/!"
  echo !str!
  endlocal
)
pause


What next?

Regards
aGerman

fabio.geraci
Posts: 4
Joined: 11 Jan 2011 02:20

Re: Set list of sobfolder as string

#8 Post by fabio.geraci » 12 Jan 2011 02:46

aGerman

thanks, I will have a go at it and report

Post Reply