Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: multipule lines as a var  (Read 6582 times)

0 Members and 1 Guest are viewing this topic.

dakota

  • Guest
multipule lines as a var
« on: June 26, 2006, 10:33:57 AM »
when i do this line and i echo the %%a it show all of the itomes but when it is set to a var it only does the first line

this is the line
Code: [Select]
for /f "tokens=1 delims= " %%a in ('dir /AD ^| findstr /R /V "\.\>" ^| find /c "<DIR>"') do set dirs=%%a
echo %dirs%
pause
for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a

echo %list%

dakota

  • Guest
Re: multipule lines as a var
« Reply #1 on: June 26, 2006, 01:21:17 PM »
any help :-? :-? :-? :-?

dakota

  • Guest
Re: multipule lines as a var
« Reply #2 on: June 26, 2006, 09:30:19 PM »
please help

ghostdog74



    Specialist

    Thanked: 27
    Re: multipule lines as a var
    « Reply #3 on: June 26, 2006, 10:56:11 PM »
    when you do the set var = %%a , you should do something with it.

    dakota

    • Guest
    Re: multipule lines as a var
    « Reply #4 on: June 26, 2006, 11:45:13 PM »
    what do you mean i  set the list to a var and when i echo it it only gets the first line so my line looks like this

    for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a & set list=%%a

    dakota

    • Guest
    Re: multipule lines as a var
    « Reply #5 on: June 26, 2006, 11:46:21 PM »
    and i use the list var latter

    uli_glueck

    • Guest
    Re: multipule lines as a var
    « Reply #6 on: June 27, 2006, 12:08:06 AM »

    You have to use a sub - procedure.

    for /f "skip=%dirs%" %%a in ('dir /b /o:g') do call :sub %%a

    set dirs=
    goto :eof
    :sub %%a

    set  dirs=%1
    pause
    for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a

    echo %list%

    hope it helps
    uli

    dakota

    • Guest
    Re: multipule lines as a var
    « Reply #7 on: June 27, 2006, 09:36:38 AM »
    ok think you but i still cant get it to work here is all of my code:
    Code: [Select]
    @echo off
    :start
    ::================================================
    set fup=fup
    set pur=purge
    set alt=altpr
    set sec=secure
    set cod=,code 100
    set ccc=,"cccc"
    set Infile=temp.dak
    set Outfile=purge.jim
    ::================================================
    for /f "tokens=1 delims= " %%a in ('dir /AD ^| findstr /R /V "\.\>" ^| find /c "<DIR>"') do set dirs=%%a
    echo %dirs%
    pause
    ::for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %fup% %pur% %%a >testttt.txt& set list=%%a

    for /f "skip=%dirs%" %%a in ('dir /b /o:g') do call :sub %%a
    set dirs=
    goto :eof
    :sub %%a
    set  dirs=%1
    for /f "skip=%dirs%" %%a in ('dir /b /o:g') do echo %%a  
    echo %list%

    pause
    ::for /f "delims=" %%a in ("%list%") do echo %fup% %pur% %%a>>%Outfile%
    ::echo.>>%Outfile%
    ::for /f "delims=" %%a in ("%list%") do echo %fup% %alt% %%a %cod%>>%Outfile%
    ::echo.>>%Outfile%
    ::for /f "delims=" %%a in ("%list%") do echo %fup% %sec% %%a %ccc%>>%Outfile%
    ::echo.>>%Outfile%
    ::pause

    dakota

    • Guest
    Re: multipule lines as a var
    « Reply #8 on: June 27, 2006, 08:56:49 PM »
    anyone

    GuruGary



      Adviser
      Re: multipule lines as a var
      « Reply #9 on: June 27, 2006, 10:03:19 PM »
      What are you trying to accomplish?  Let me know and I will be glad to help.

      dakota

      • Guest
      Re: multipule lines as a var
      « Reply #10 on: June 27, 2006, 11:53:19 PM »
      I am trying to get a list of all the files in a directory and output them to a file but I want this list to be in the bare formate and have no folders included in it just the files. :P ::) ;D ;D Think you

      ghostdog74



        Specialist

        Thanked: 27
        Re: multipule lines as a var
        « Reply #11 on: June 28, 2006, 02:46:36 AM »
        @echo off

        for /F %%i in ('dir /A-D /S /B') do (
              echo %%~ni >> output.txt
        )

        uli_glueck

        • Guest
        Re: multipule lines as a var
        « Reply #12 on: June 28, 2006, 02:57:35 AM »
        So you don`t need to set it in a variable.
        Ghostdogs solution seems perfect. :-)
        « Last Edit: June 28, 2006, 02:58:07 AM by uli_glueck »

        dakota

        • Guest
        Re: multipule lines as a var
        « Reply #13 on: June 28, 2006, 10:08:22 AM »
        nope that dose not work i need it not to display directorys but all of the files and i would like to have it in a var because i will use the var later when i am adding things to it the it will go to the output file.

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: multipule lines as a var
        « Reply #14 on: June 28, 2006, 01:24:33 PM »
        After reading this post, I'm guessing you want one variable to hold all the file names as if it were a collection. You can accomplish this by concatenating the files/dir names out of the FOR:

        call set list=%list%%%a

        Unfortunately, the result will be one long string. Unless you're running MS-DOS as your operating system and have access to the ANSI.SYS driver, there is no way to insert CRLF (carriage return/linefeed) characters between the file names in batch language.

        Try using one of the Windows scripting languages where you have access to functions to represent the CRLF characters.

         8-)
        « Last Edit: June 28, 2006, 02:07:07 PM by Sidewinder »
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein