Page 1 of 1

Set list of sobfolder as string

Posted: 11 Jan 2011 02:37
by fabio.geraci
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

Re: Set list of sobfolder as string

Posted: 11 Jan 2011 03:20
by !k

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

Re: Set list of sobfolder as string

Posted: 11 Jan 2011 04:53
by fabio.geraci
Thanks,

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

cheers

Re: Set list of sobfolder as string

Posted: 11 Jan 2011 11:30
by aGerman
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

Re: Set list of sobfolder as string

Posted: 11 Jan 2011 13:05
by fabio.geraci
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.

Re: Set list of sobfolder as string

Posted: 11 Jan 2011 13:11
by avery_larry
but not everybody has a python at the office.

So true, so true.


:lol:

Re: Set list of sobfolder as string

Posted: 11 Jan 2011 15:22
by aGerman
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

Re: Set list of sobfolder as string

Posted: 12 Jan 2011 02:46
by fabio.geraci
aGerman

thanks, I will have a go at it and report