This is not vbscript, but may be helpful. This script is in biterscripting. It will create a tab-separated Excel file from all *.txt files under a given directory. The excel file will be created in this format - one entry per line.
Code:
user <tab> total memory <tab> comp model <tab> processor
<tab> free disk space < tab> total disk space
The script will handle the presence or absence of colon :. I am adding comments to the script so you can translate it to vbscript if necessary.
Code:
# Script CompInventory.txt
# Input arguments
var string dir # Top directory under which to search *.txt files.
var string outfile # Path to the output file
var string list, file, input, output
var str user, totmem, compmodel, processor, freediskspace, totdiskspace
cd $dir # Change directory.
lf -n "*.txt" > $list # Collect list of *.txt files.
while ($list <> "") # Process files one by one.
do
lex "1" $list > $file # Get the next file.
cat $file > $input # Read file into a string variable
# Discard everything upto "RegisteredUser:"
stex -c "^RegisteredUser:^]" $input > null
stex "]^\n^" $input > $user # Till the newline is the user
# Discard everything upto total memory line
stex -r -c "^Memory and Processor Information&\n&\n&\n^]" $input > null
wex "1" $input > $totmem # Next word is total memory
stex -r "^\n&\:^]" $input > null # Discard up to next colon
stex "]^\n^" $input > $compmodel # Till the newline is the computer model
stex "^:^]" $input > null # Discard up to next colon
stex "]^\n^" $input > $processor # Till the next newline is processor
# Discard everything upto free disk space line
stex -r -c "^Disk Drive Information&\n&\n&\n^]" $input > null
wex "1" $input > $freediskspace # Next word is free disk space
stex "^\n^]" $input > null # Discard up to next line
wex "1" $input > $totdiskspace # Next word is total disk space
# We have all the info items. Write to $output. Also show it to user.
echo $user "\t" $totmem "\t" $compmodel "\t" $processor "\t" $freediskspace "\t" $totdiskspace
echo $user "\t" $totmem "\t" $compmodel "\t" $processor "\t" $freediskspace "\t" $totdiskspace >> $output
done
# Write output to output file given by user.
echo $output > { echo $outfile }
I have tested the script. To test, copy and paste the script code into file C:/Scripts/CompInventory.txt, start biterscripting, and copy and paste this command
Code:
script "C:/Scripts/CompInventory.txt" dir("C:/test") outfile("C:/test/output.xls")
This is assuming C:/test is where the test files are. The output will be shown on screen as well as written to file C:/test/output.xls. Open the output .xls file as usual.
Bookmarks