How To Append Server Name to DIR Batch File

July 13, 2009 at 10:40:58
Specs: Windows Vista
I created a batch file which would create a directory of a specific drive letter on each of the (6) servers I'm trying to account for.
The output is just sent into an excel file I designate each time it is run.
How do I make it so the servername is echoed in the second column next to each entry returned?

Example of current file:

@echo
echo. SERVER1 >> "C:\Users\TEST\Desktop\TOOLS\CASE STATUS REPORT\CASELIST.xls"
echo The folders in your root directory:
dir /b \\SERVER1\s$ >> "C:\Users\TEST\Desktop\TOOLS\CASE STATUS REPORT\CASELIST.xls"
echo. SERVER1 >> "C:\Users\TEST\Desktop\TOOLS\CASE STATUS REPORT\CASELIST.xls"

In excel the output is like this:

col1 col2
(blank) SERVER1
FOLDER
FOLDER
FOLDER
FOLDER
FOLDER
(blank) SERVER1

How do I get the second column to to populate the servername for each corresponding entry?


See More: How To Append Server Name to DIR Batch File

Report •


#1
July 13, 2009 at 13:52:59
@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims=" %%a in ('dir/b \\SERVER1\s$') do (
echo %%a SERVER1 >> CASELIST.xls
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 14, 2009 at 08:55:04
Works perfectly, however how do specify the server name to show up in the second column next to the dir entries?

Currently:

Col1
Foldername Servername
Foldername Servername

Ideally:
col1 col2
Foldername Servername
Foldername Servername


Report •

#3
July 14, 2009 at 23:28:12
Not clear yet.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
July 15, 2009 at 09:52:43
You can't output plain text from a batch file into an Excel
spreadsheet: the latter is binary formatted.

One workaround is to use a Comma Separated Values (.csv) file
instead of an .xls file. By default the .csv file will also open in
Excel; you just won't be able to do anything fancy like different
colours or fonts.


Report •


Ask Question