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

Author Topic: Is it possible to write simple text files with batch?  (Read 3030 times)

0 Members and 1 Guest are viewing this topic.

PirateSamir

    Topic Starter


    Rookie

    Is it possible to write simple text files with batch?
    « on: April 18, 2009, 07:01:20 AM »
    I know i can use the echo command to write something but that will enable me to write something with only one line, unless i use && or ^& but thats only for if i'm writing another batch file.

    example code
    Code: [Select]
    echo hello > hello.txt
    My question is basically if i can write a file with multiple lines of text making it a simple text file?
    Quantum bonus pro quantum numerus.

    Reno



      Hopeful
    • Thanked: 32
      Re: Is it possible to write simple text files with batch?
      « Reply #1 on: April 18, 2009, 07:45:21 AM »
      >       overwrite file/create if not exist
      >>     append to file

      PirateSamir

        Topic Starter


        Rookie

        Quantum bonus pro quantum numerus.

        evan

        • Guest
        Re: Is it possible to write simple text files with batch?
        « Reply #3 on: April 18, 2009, 10:41:42 AM »
        Code: [Select]
        echo hello > hello.txt
        echo hi >> hello.txt
        echo does this work? >> hello.txt
        Notice the > in the first line and >> in all following lines.
        « Last Edit: April 18, 2009, 12:27:02 PM by evan »

        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        Re: Is it possible to write simple text files with batch?
        « Reply #4 on: April 18, 2009, 02:44:38 PM »
        The single > overwrites the previous contents of the file with what is before it.
        Example:
        echo The only line > file.ext

        The double >> does NOT overwrite the previous contents of the file, but puts the text before it at the end of the file.
        Example:
        echo The last line > file.ext

        Do you understand now?
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.

        Prince_



          Beginner

          Thanked: 5
          Re: Is it possible to write simple text files with batch?
          « Reply #5 on: April 19, 2009, 03:27:05 AM »
          (
          echo hello
          echo world
          )>a.txt

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: Is it possible to write simple text files with batch?
          « Reply #6 on: April 19, 2009, 08:18:54 AM »
          (
          echo hello
          echo world
          )>a.txt
          that's the 4 line equivilent of what can be done in 2 (or 1).

          echo hello > a.txt
          echo world >> a.txt

          or
          echo hello > a.txt & echo world >> a.txt
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          tonlo



            Rookie

            Re: Is it possible to write simple text files with batch?
            « Reply #7 on: April 19, 2009, 08:49:06 AM »
            like Helpmeh, you can move ">" to begin of your command.
            >  a.txt echo hello
            >>a.txt echo world
            >>a.txt echo does this work?


            Helpmeh



              Guru

            • Roar.
            • Thanked: 123
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            Re: Is it possible to write simple text files with batch?
            « Reply #8 on: April 19, 2009, 01:17:35 PM »
            like Helpmeh, you can move ">" to begin of your command.
            >  a.txt echo hello
            >>a.txt echo world
            >>a.txt echo does this work?


            I have never tried it that way...
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.