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

Author Topic: Batch - append text to output of another command  (Read 3318 times)

0 Members and 1 Guest are viewing this topic.

stage

    Topic Starter


    Newbie

    Batch - append text to output of another command
    « on: May 10, 2009, 03:52:34 AM »
    Hello,

    I am using this;
    Code: [Select]
    :: List all the .doc files in a directory
    DIR /b /o "c:\some_directory\*.doc">>filenames.txt

    Which generates a nice list like this;
    file1.doc
    another file.doc
    third file.doc


    This is lovely and has made me happy, but the simple question is how do I append a 'tab' character and some text to this nice list to give me the following output in my filenames.txt file;
    file1.doc   tab   text_in_here
    another file.doc   tab   text_in_here
    third file.doc   tab   text_in_here


    Its driving me mad!!

    Many thanks for any help,

    Cheers,

    Stage

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: Batch - append text to output of another command
      « Reply #1 on: May 10, 2009, 06:11:07 AM »
      you can use for loop together with your dir command.
      as an alternative solution, you can use this vbscript
      Code: [Select]
      Set objFS = CreateObject("Scripting.FileSystemObject")
      strFolder = "c:\some_directory"
      Set objFolder = objFS.GetFolder(strFolder)
      For Each strFile In objFolder.Files
      If objFS.GetExtensionName(strFile) ="doc" Then
      WScript.Echo strFile.Name & vbTab & "some words"
      End If
      Next

      save as myscript.vbs and on command line
      Code: [Select]
      C:\test> cscript /nologo myscript.vbs > newfile

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: Batch - append text to output of another command
      « Reply #2 on: May 10, 2009, 09:45:38 AM »
      Hello,

      I am using this;
      Code: [Select]
      :: List all the .doc files in a directory
      DIR /b /o "c:\some_directory\*.doc">>filenames.txt

      Which generates a nice list like this;
      file1.doc
      another file.doc
      third file.doc


      This is lovely and has made me happy, but the simple question is how do I append a 'tab' character and some text to this nice list to give me the following output in my filenames.txt file;
      file1.doc   tab   text_in_here
      another file.doc   tab   text_in_here
      third file.doc   tab   text_in_here


      Its driving me mad!!

      Many thanks for any help,

      Cheers,

      Stage
      As gh0st said, you could use a for loop, as demonstrated here:

      Code: [Select]
      for /f "delims= " %%A in ('DIR /b /o c:\some_directory\*.doc') do echo %%A text_here>>filenames.txt
      That should work as long as the filenames or the path don't contain spaces.
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      stage

        Topic Starter


        Newbie

        Re: Batch - append text to output of another command
        « Reply #3 on: May 10, 2009, 12:53:35 PM »
        Hey there,

        Perfect. Thanks so much. I've learnt alot just in this one exercise.
        Helpmeh answer does work ok with spaces in filenames but not spaces in directories. This is not a problem.

        Cheers,


        Stage

        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        Re: Batch - append text to output of another command
        « Reply #4 on: May 10, 2009, 12:58:56 PM »
        Hey there,

        Perfect. Thanks so much. I've learnt alot just in this one exercise.
        Helpmeh answer does work ok with spaces in filenames but not spaces in directories. This is not a problem.

        Cheers,


        Stage
        Ok, I wasn't sure if it would work properly with spaces. I did it all free-thought (without debugging at all).
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.