1.

Solve : Batch - append text to output of another command?

Answer» 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,

Stageyou 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
Quote from: stage 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
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.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,


StageQuote from: stage 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
Ok, I wasn't sure if it would work properly with spaces. I did it all free-thought (without debugging at all).


Discussion

No Comment Found