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

Author Topic: How can I save output of dir in a variable?  (Read 22195 times)

0 Members and 1 Guest are viewing this topic.

sipungora

    Topic Starter


    Rookie

    How can I save output of dir in a variable?
    « on: September 08, 2008, 03:09:51 AM »
    Hi all,

    output of dir can be re-routed into myfile with "dir > myfile ".
    How can I re-route it into a variable?

    Thanks beforehand,
    regards.

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: How can I save output of dir in a variable?
    « Reply #1 on: September 08, 2008, 03:44:45 AM »
    You don't so much redirect output to a variable as to construct a variable from the pieces of the output.

    Code: [Select]
    @echo off
    for /f "delims=" %%a in ('dir c:\temp') do (
    call set concat=%%concat%%%%a
    )
    echo %concat%

    Be sure to change the directory name. 8)

    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    sipungora

      Topic Starter


      Rookie

      Re: How can I save output of dir in a variable?
      « Reply #2 on: September 08, 2008, 04:54:12 AM »
      Thank you, Sidewinder, very much.

      You've solved all my problems, that I had with my batch file. ;D ;D ;D

      Best regards. :)