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

Author Topic: How to output echo'd info from a for loop  (Read 3316 times)

0 Members and 1 Guest are viewing this topic.

Handler

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Other
    How to output echo'd info from a for loop
    « on: April 17, 2017, 03:04:03 PM »
    Hello!

    Fairly simple problem that I can't figure out.  :(

    I managed to get this far :

    Code: [Select]
    for %F in ("e:\*") do @echo %F=:=%~zF
    Which does what I want.  The =:= is there just so I have something to explode off of when reading this in to a PHP script.  Now I tried using the > filename.txt to direct the output to a file but in the end I would only get the name of the that file "filename.txt" and it's file size.

    This will be my one learned thing for the day!  ;D

    Thanks for any and all help, super appreciated!

    Dave

    Hackoo



      Hopeful
    • Thanked: 42
    • Experience: Expert
    • OS: Windows 10
    Re: How to output echo'd info from a for loop
    « Reply #1 on: April 17, 2017, 09:02:18 PM »
    Hi  ;)

    So what is the result of those commands ?

    Code: [Select]
    for %F in ("e:\*") do @echo %F=:=%~zF > e:\File_Size1.txt
    and this :

    Code: [Select]
    for %F in ("e:\*") do @echo %F=:=%~zF >> e:\File_Size2.txt

    Handler

      Topic Starter


      Newbie

      • Experience: Experienced
      • OS: Other
      Re: How to output echo'd info from a for loop
      « Reply #2 on: April 19, 2017, 09:24:46 AM »
      Sorry I didn't respond earlier but yes it seems that second option does work and lists all the files in that directory the first just shows the last file.  Which leads me to believe it just kept over writing the file every time. Ugh!

      Thanks for getting me un-stuck!  ;D

      strollin



        Adviser
      • Thanked: 84
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Guru
      • OS: Windows 10
      Re: How to output echo'd info from a for loop
      « Reply #3 on: April 21, 2017, 09:39:27 PM »
      As you found, a single chevron > overwrites the file while double chevrons append.  I've found it works best to write the batch file in such a way that the first file echoed to the file is done with one >, while the rest are echoed with two >>.  That way, I get a new file each time but I still get everything.

      You could also just delete the file first, then use >> to do the echoing.