Reading Columns & Output
Moderator: DosItHelp
Re: Reading Columns & Output
abc0502
foxidrive
This is way tooo much fun an energizing!
this code:
md c:\temp1 2>nul
cd /d c:\temp1
cls
As I try to understand it, can be used to create a folder on the root of drive C:.
maybe I was thinking too hard into this module I was trying to build out. Anway, I see some items that I am not used to see and using, but am really grateful for your support.
I don't know if this forum never existed I still be outside fishing . .. . I would have to say there are some levels to batch'n that never existing, lol, koo-dos again, thank you. . ..
Koo-dos to all who aided, everybody gets ponts on this/ how do I submit "finish" on this?
g'nite . .. .
foxidrive
This is way tooo much fun an energizing!
this code:
md c:\temp1 2>nul
cd /d c:\temp1
cls
As I try to understand it, can be used to create a folder on the root of drive C:.
maybe I was thinking too hard into this module I was trying to build out. Anway, I see some items that I am not used to see and using, but am really grateful for your support.
I don't know if this forum never existed I still be outside fishing . .. . I would have to say there are some levels to batch'n that never existing, lol, koo-dos again, thank you. . ..
Koo-dos to all who aided, everybody gets ponts on this/ how do I submit "finish" on this?
g'nite . .. .
Re: Reading Columns & Output
Ocalabob, thank you for your time and your insight into your help.
best regards, Booga73
best regards, Booga73
Re: Reading Columns & Output
forgot, . . . .
what does this equate to?
.. .. >> myResults2.txt ECHO "!field:~0,10!","!field:~13,7!","!field:~21,17!","!field:~39,12!","!field:~52,23!","!field:~75!"
is this 8 tokens residing in a .csv file with specific field widths?
that's all I wanted to know, thank you. . . v/r Booga73
what does this equate to?
.. .. >> myResults2.txt ECHO "!field:~0,10!","!field:~13,7!","!field:~21,17!","!field:~39,12!","!field:~52,23!","!field:~75!"
is this 8 tokens residing in a .csv file with specific field widths?
that's all I wanted to know, thank you. . . v/r Booga73
Re: Reading Columns & Output
booga73 wrote:what does this equate to?
.. .. >> myResults2.txt ECHO "!field:~0,10!","!field:~13,7!","!field:~21,17!","!field:~39,12!","!field:~52,23!","!field:~75!"
is this 8 tokens residing in a .csv file with specific field widths?
Yes. first token = skip 0 characters from the field environment variable, take the next 10 characters.
second token = skip 13 characters, take the next 7 characters.
...
Last token = skip 75 characters, take the rest of the line.
Re: Reading Columns & Output
Edited:
Changed the "HTML_P1" Function and added few CSS Styles to make the Table Easy to Read.
This won't work if a file has parentheses
Ok, This is my version ,I know Foxidrive solved it, but i couldn't get it out of my head unless i finish it.
It can create HTML table, you can take this part and join it with Foxidrive code.
The First 3 Variable You should Set Them to suite you, the rest is not that important to you.
One last Note, it can't extract the Short File Names
> Comment the delete commands in the clean section to have a look at the files the batch create.
> Few notes on the Batch i was writing while coding, might help you some how
Changed the "HTML_P1" Function and added few CSS Styles to make the Table Easy to Read.
This won't work if a file has parentheses
Ok, This is my version ,I know Foxidrive solved it, but i couldn't get it out of my head unless i finish it.
It can create HTML table, you can take this part and join it with Foxidrive code.
The First 3 Variable You should Set Them to suite you, the rest is not that important to you.
One last Note, it can't extract the Short File Names
Code: Select all
@Echo off
REM ==== Settings ==========================================================
SET "Main=%userprofile%\Desktop\DIR List"
SET "Directory=C:\Windows"
SET "maxlines=116"
SET "DirDataFile=%Main%\All.txt"
SET "TempFolder=%Main%\tmp"
SET "HTMLfile=%Main%\Report.html"
REM ==== Collect Information ===============================================
REM This file is self-overwrite
DIR "%Directory%" /t:caw /q /a /o:-g-ds |FIND "/" > "%DirDataFile%"
REM code start to identify number of lines in a text
SET /A LineNumb=0
For /F %%a in ('FIND /c /v "" ^< "%DirDataFile%"') Do SET /A LineNumb=%%a
Echo %DirDataFile% has %LineNumb% lines.
REM ==== Nullifing Errors ==================================================
IF "%maxlines%" == "" SET "maxlines=%LineNumb%"
IF NOT EXIST "%TempFolder%" MD "%TempFolder%" >NUL
REM ==== Extract Data From Columns =========================================
SETLOCAL EnableDelayedExpansion
SET "linecount=0"
FOR /F "delims=" %%b IN ('Type "%DirDataFile%"') DO (
IF "!linecount!" EQU "%maxlines%" GOTO ExitLoop
SET "field=%%b"
SET "Date=!field:~0,10!"
SET "Time=!field:~12,8!"
SET "Type=!field:~24,5!"
SET "SNO=!field:~27!"
REM Extract Date and Time
Echo !Date!;!Time!;>>"%TempFolder%\Part1.txt"
REM Extract Type [ we can write only DIR or we can't create the HTML FILE ]
IF "!Type:~0,2!" == "<D" ( Echo DIR;>>"%TempFolder%\Part2.txt"
) Else ( Echo X;>>"%TempFolder%\Part2.txt" )
REM This will extract Size, File Owner and File name
CALL :Process "!SNO!"
SET /A linecount+=1
)
REM ==== Combine All 4 Part Files in one delimeted File ====================
:ExitLoop
Rem combine part 1 and 2 in out1
CALL :Combine "%TempFolder%\Part1.txt" "%TempFolder%\Part2.txt" "%TempFolder%\Out1.txt"
Rem combine part 3 and 4 in tmp2
CALL :Combine "%TempFolder%\Part3.txt" "%TempFolder%\Part4.txt" "%TempFolder%\tmp2.txt"
Rem combine part tmp2 and part5 in out2
CALL :Combine "%TempFolder%\tmp2.txt" "%TempFolder%\Part5.txt" "%TempFolder%\out2.txt"
Rem combine out 1 and 2 in final
CALL :Combine "%TempFolder%\out1.txt" "%TempFolder%\out2.txt" "%Main%\final.txt"
REM ==== Generate HTML File ================================================
REM remove previous html file
IF EXIST "%HTMLfile%" DEL /F /Q "%HTMLfile%" >NUL
REM html file part 1
CALL :HTML_P1
REM html file rows
SETLOCAL EnableDelayedExpansion
For /F "tokens=1-6 delims=;" %%A In ('Type "%main%\final.txt"') Do (
SET "Date=%%A"
SET "Time=%%B"
SET "Type=%%C"
SET "Size=%%D"
SET "Owner=%%E"
SET "Name=%%F"
CALL :Row "!Date!" "!Time!" "!Type!" "!Size!" "!Owner!" "!Name!"
)
REM html file part 2
CALL :HTML_P2
REM ==== Clean =============================================================
RMDIR /S /Q "%main%\tmp"
DEL /F /Q "%DirDataFile%"
rem Del /F /Q "%main%\final.txt"
Pause
Exit /B
:Process <Text>
For /F "tokens=1-3* delims= " %%A In ("%~1") Do (
REM Extract Size [ always 1st token ]
SET "Size=%%A"
IF NOT "!Size:~0,2!" == "R>" ( Echo !Size!;>>"%TempFolder%\Part3.txt"
) Else ( Echo X;>>"%TempFolder%\Part3.txt" )
REM Extract Owner [ might be 2nd or 2nd and 3rd ]
SET "Owner=%%B"
IF /I "!Owner:~0,2!" == "NT" ( Echo %%B %%C;>>"%TempFolder%\Part4.txt"
) Else ( Echo %%B;>>"%TempFolder%\Part4.txt" )
REM Extract
IF /I "!Owner:~0,2!" == "NT" ( Echo %%D;>>"%TempFolder%\Part5.txt"
) Else ( Echo %%C %%D;>>"%TempFolder%\Part5.txt" )
)
GOTO :EOF
:Combine <1st_file> <2nd_file> <out_file> <Optinional_Separator>
SET "F1=%~1"
SET "F2=%~2"
SET "Out=%~3"
SET "Separator=%~4"
IF NOT Defined Seprator SET "Separator="
(
FOR /F "delims=" %%A IN ('Type "%F1%"') DO (
SETLOCAL EnableDelayedExpansion
SET /P line=
Echo.%%A!Separator!!line!
ENDLOCAL
)
)<"%F2%">>"%Out%"
GOTO :EOF
:HTML_P1
(
Echo ^<HTML^>
Echo ^<head^>
Echo ^<style media="screen" type="text/css"^>
Echo html {
Echo background-color: Black;
Echo color: Orange;
Echo }
Echo.
Echo table {
Echo border: 2px solid red;
Echo padding: 2px;
Echo }
Echo.
Echo td {
Echo width: 120px;
Echo height: 30px;
Echo border: 1px solid gray;
Echo }
Echo ^</style^>
Echo ^</head^>
Echo ^<body^>
Echo ^<table^>
)>>"%HTMLfile%"
GOTO :EOF
:Row <take_the_6_data_fields>
(
Echo ^<tr^>
Echo ^<td^>%~1^</td^>
Echo ^<td^>%~2^</td^>
Echo ^<td^>%~3^</td^>
Echo ^<td^>%~4^</td^>
Echo ^<td^>%~5^</td^>
Echo ^<td^>%~6^</td^>
Echo ^</tr^>
)>>"%HTMLfile%"
GOTO :EOF
:HTML_P2
(
Echo ^</table^>
Echo ^</body^>
Echo ^</html^>
)>>"%HTMLfile%"
GOTO :EOF
> Comment the delete commands in the clean section to have a look at the files the batch create.
> Few notes on the Batch i was writing while coding, might help you some how
All Bold Words are supposed to be a Variable Names.Date and time has a fixed length.
In the type i only check if the token start with <D, if so i will echo the word "DIR" to the file not the token in case there was any other characters in that token.
The size, File owner and file name will be processed using the function ":Process", it will use "one space" as a delims and.
The first token "%%A" will be file size.
The owner will be 2nd token only or 2nd and 3rd so we check if it start with NT word (it means 2nd and 3rd token) or doesn't start with it (it means 2nd token only)
The File name will be 3rd token or 4th token, if the
2nd token was start with "NT" it means the 4th token else it will be 3rd.
Last edited by abc0502 on 13 Feb 2013 01:55, edited 2 times in total.
Re: Reading Columns & Output
abc0502: After I create the required folder, I get the HTML file but it's missing a lot of entries, and closing tags, and has an X.
It fails with:
.log</td> was unexpected at this time.
It fails with:
.log</td> was unexpected at this time.
Code: Select all
<HTML>
<head> </head>
<body>
<table>
<tr>
<td>13/02/2013</td>
<td>04:14 PM</td>
<td>X</td>
<td> 1,897,996</td>
<td>NT AUTHORITY\SYSTEM</td>
<td>WindowsUpdate.log</td>
</tr>
<tr>
<td>10/02/2013</td>
<td>04:49 AM</td>
<td>X</td>
<td> 67,584</td>
<td>NT AUTHORITY\SYSTEM</td>
<td>bootstat.dat</td>
</tr>
<tr>
<td>05/02/2013</td>
<td>01:48 AM</td>
<td>X</td>
<td> 1,604,476</td>
<td>NT AUTHORITY\SYSTEM</td>
<td>setupact.log</td>
</tr>
<tr>
<td>03/02/2013</td>
<td>10:45 PM</td>
<td>X</td>
<td> 9,556</td>
<td>BUILTIN\Administrators</td>
<td> PFRO.log </td>
</tr>
<tr>
<td>29/01/2013</td>
<td>09:19 PM</td>
<td>X</td>
<td> 17,510</td>
<td>BUILTIN\Administrators</td>
<td> wincmd.ini </td>
</tr>
<tr>
<td>06/11/2012</td>
<td>03:20 PM</td>
<td>X</td>
<td> 788,480</td>
<td>NT SERVICE\TrustedInstaHelpPane.exe</td>
<td></td>
</tr>
<tr>
<td>03/11/2012</td>
<td>01:46 AM</td>
<td>X</td>
<td> 22,863</td>
<td>...</td>
<td> diagerr.xml </td>
</tr>
<tr>
<td>03/11/2012</td>
<td>01:46 AM</td>
<td>X</td>
<td> 22,863</td>
<td>...</td>
<td> diagwrn.xml </td>
</tr>
<tr>
<td>03/11/2012</td>
<td>01:46 AM</td>
<td>X</td>
<td> 6,633</td>
<td>BUILTIN\Administrators</td>
<td> comsetup.log </td>
</tr>
<tr>
<td>03/11/2012</td>
<td>01:44 AM</td>
<td>X</td>
<td> 3,960</td>
<td>NT AUTHORITY\SYSTEM</td>
<td>DtcInstall.log</td>
</tr>
<tr>
<td>03/11/2012</td>
<td>01:43 AM</td>
<td>X</td>
<td> 0</td>
<td>BUILTIN\Administrators</td>
<td> ativpsrm.bin </td>
</tr>
Re: Reading Columns & Output
I forgot to add the CSS styling ,i added it now,but did you copied the entire code?
The X is when there was empty space i couldn't echo it so added X
The X is when there was empty space i couldn't echo it so added X
Re: Reading Columns & Output
I just tried your latest code - see my post above, which I updated.
Re: Reading Columns & Output
It's failing on (1) here I suspect.
03/11/2012 01:13 AM 1,367,641 BUILTIN\Administrators WindowsUpdate (1).log
03/11/2012 01:13 AM 1,367,641 BUILTIN\Administrators WindowsUpdate (1).log
Re: Reading Columns & Output
The Parentheses explain every thing, while i was taking the <DIR> it was failling and when i removed the < and > every thing was fixed.
the code can't escape them.
the code can't escape them.
Re: Reading Columns & Output
You can process them in a for /f loop.
But check this and see if you want to add a HTML section.
ATM it creates a CSV file with all the entries but the owner entries have trailing spaces.
This is what it produces:
Code: Select all
@echo off
set "var=<>()&^!!| etc"
for /f "delims=" %%a in ("%var%") do echo %%a
pause
But check this and see if you want to add a HTML section.
ATM it creates a CSV file with all the entries but the owner entries have trailing spaces.
Code: Select all
:: beginning of batch file
@Echo off
dir c:\windows\ /t:caw /r /x /q /a /o:-g-ds |find "/" > WinDir1.txt
:: code start to identify number of lines in a text
Set FileName=WinDir1.txt
Set /a LineNumb=0
for /f %%a in ('find /c /v "" ^< %FileName%') do set /a LineNumb=%%a
Echo %FileName% has %LineNumb% lines.
:: code end to identify number of lines in a text
setlocal enabledelayedexpansion
SET /A maxlines=116
SET /A linecount=0
del myResults.csv 2>nul
FOR /F "delims=" %%b IN (WinDir1.txt) DO (
IF !linecount! EQU %maxlines% GOTO ExitLoop
set "field=%%b"
call :next "!field:~0,10!" "!field:~13,7!" "!field:~21,17!" "!field:~39,12!" "!field:~52,23!" "!field:~75!"
SET /A linecount+=1
)
:ExitLoop
del WinDir1.txt
goto :EOF
:next
set "line="
set c=0
:next2
set /a c=c+1
set tokens="tokens=*"
if %c% EQU 3 set tokens=
for /f %tokens% %%a in ("%~1") do call set line=%%line%%,"%%a"
shift
if not "%~1"=="" goto :next2
>> myResults.csv echo %line:~1%
:: end of subroutine
:: end of batch file
This is what it produces:
Code: Select all
"13/02/2013","4:14 PM","1,897,996","WINDOW~1.LOG","NT AUTHORITY\SYSTEM ","WindowsUpdate.log"
"10/02/2013","4:49 AM","67,584","","NT AUTHORITY\SYSTEM ","bootstat.dat"
"05/02/2013","1:48 AM","1,604,476","","NT AUTHORITY\SYSTEM ","setupact.log"
"03/02/2013","0:45 PM","9,556","","BUILTIN\Administrators ","PFRO.log"
"29/01/2013","9:19 PM","17,510","","BUILTIN\Administrators ","wincmd.ini"
"06/11/2012","3:20 PM","788,480","","NT SERVICE\TrustedInsta","HelpPane.exe"
"03/11/2012","1:46 AM","22,863","","... ","diagerr.xml"
"03/11/2012","1:46 AM","22,863","","... ","diagwrn.xml"
"03/11/2012","1:46 AM","6,633","","BUILTIN\Administrators ","comsetup.log"
"03/11/2012","1:44 AM","3,960","DTCINS~1.LOG","NT AUTHORITY\SYSTEM ","DtcInstall.log"
"03/11/2012","1:43 AM","0","","BUILTIN\Administrators ","ativpsrm.bin"
"03/11/2012","1:13 AM","1,367,641","WINDOW~2.LOG","BUILTIN\Administrators ","WindowsUpdate (1).log"
"03/11/2012","1:08 AM","1,945","EPPLAU~1.MIF","BUILTIN\Administrators ","epplauncher.mif"
"01/11/2012","2:07 PM","4,578","","BUILTIN\Administrators ","wcx_ftp.ini"
"11/10/2012","4:56 PM","2,115,952","","NT SERVICE\TrustedInsta","explorer.exe"
"01/10/2012","9:57 AM","453","","BUILTIN\Administrators ","INSTALL.LOG"
"31/08/2012","2:32 AM","63","ALTAIR~1.INI","BUILTIN\Administrators ","Altair_1.250.INI"
"02/08/2012","4:27 AM","917,748","","BUILTIN\Administrators ","ntbtlog.txt"
"26/07/2012","5:09 PM","1,585","VMGCOI~1.LOG","NT AUTHORITY\SYSTEM ","vmgcoinstall.log"
"26/07/2012","5:03 PM","0","","NT AUTHORITY\SYSTEM ","setuperr.log"
"26/07/2012","3:17 PM","219","","NT AUTHORITY\SYSTEM ","system.ini"
"26/07/2012","2:21 PM","9,728","","NT SERVICE\TrustedInsta","write.exe"
"26/07/2012","2:21 PM","10,752","","NT SERVICE\TrustedInsta","winhlp32.exe"
"26/07/2012","2:20 PM","30,208","","NT SERVICE\TrustedInsta","twunk_32.exe"
"26/07/2012","2:20 PM","109,056","","NT SERVICE\TrustedInsta","splwow64.exe"
"26/07/2012","2:20 PM","133,120","","NT SERVICE\TrustedInsta","regedit.exe"
"26/07/2012","2:20 PM","233,984","","NT SERVICE\TrustedInsta","notepad.exe"
"26/07/2012","2:20 PM","15,872","","NT SERVICE\TrustedInsta","hh.exe"
"26/07/2012","2:20 PM","68,608","","NT SERVICE\TrustedInsta","bfsvc.exe"
"26/07/2012","2:20 PM","50,176","","NT SERVICE\TrustedInsta","twain_32.dll"
"26/07/2012","7:41 AM","43,131","","NT SERVICE\TrustedInsta","mib.bin"
"26/07/2012","7:18 AM","15,901","PROFES~2.XML","BUILTIN\Administrators ","ProfessionalWMC.xml"
"26/07/2012","7:18 AM","15,769","","NT AUTHORITY\SYSTEM ","Starter.xml"
"26/07/2012","7:18 AM","15,941","PROFES~1.XML","BUILTIN\Administrators ","Professional.xml"
"20/07/2012","2:02 AM","152","","BUILTIN\Administrators ","pkplugin.ini"
"15/07/2012","1:27 PM","2,216,480","","BUILTIN\Administrators ","wweb32.dll"
"18/06/2012","1:35 AM","2,456,576","{DE779~1 ","BUILTIN\Administrators ","{DE779690-B876-11E1-8273-00241D23F809}"
"17/06/2012","0:27 PM","1,851,904","{C3621~1 ","BUILTIN\Administrators ","{C3621EC7-B86B-11E1-80AB-00241D23F809}"
"03/06/2012","1:46 AM","707","","NT SERVICE\TrustedInsta","_default.pif"
"03/06/2012","1:46 AM","256,192","","NT SERVICE\TrustedInsta","winhelp.exe"
"03/06/2012","1:37 AM","49,680","","NT SERVICE\TrustedInsta","twunk_16.exe"
"03/06/2012","1:37 AM","94,784","","NT SERVICE\TrustedInsta","twain.dll"
"03/06/2012","1:34 AM","316,640","","NT SERVICE\TrustedInsta","WMSysPr9.prx"
"03/06/2012","1:32 AM","670","","NT SERVICE\TrustedInsta","WindowsShell.Manifest"
"17/05/2012","4:24 PM","793","","... ","XXCLONE.INI"
"12/05/2012","6:53 PM","303","","BUILTIN\Administrators ","SynInst.log"
"12/05/2012","6:21 PM","1,355","TSSYSP~1.LOG","NT AUTHORITY\SYSTEM ","TSSysprep.log"
"09/03/2012","8:57 AM","545","","BUILTIN\Administrators ","PKUNZIP.PIF"
"09/03/2012","8:57 AM","545","","BUILTIN\Administrators ","PKZIP.PIF"
"09/03/2012","8:57 AM","545","","BUILTIN\Administrators ","NOCLOSE.PIF"
"09/03/2012","8:57 AM","545","","BUILTIN\Administrators ","RAR.PIF"
"09/03/2012","8:57 AM","545","","BUILTIN\Administrators ","ARJ.PIF"
"09/03/2012","8:57 AM","545","","BUILTIN\Administrators ","LHA.PIF"
"09/03/2012","8:57 AM","545","","BUILTIN\Administrators ","UC.PIF"
"18/06/2011","6:03 AM","66","","BUILTIN\Administrators ","W7T.txt"
"14/07/2009","3:54 PM","403","","NT AUTHORITY\SYSTEM ","win.ini"
"14/07/2009","2:14 PM","9,728","","NT SERVICE\TrustedInsta","winhlp32.exe.org"
"11/06/2009","8:19 AM","1,405","","NT AUTHORITY\SYSTEM ","msdfmap.ini"
"13/02/2013","5:37 PM","<DIR>","","... ","Prefetch"
"13/02/2013","3:35 AM","<DIR>","","... ","Temp"
"13/02/2013","3:33 AM","<DIR>","MICROS~1.NET","NT SERVICE\TrustedInsta","Microsoft.NET"
"08/02/2013","2:46 PM","<DIR>","","NT AUTHORITY\SYSTEM ","CbsTemp"
"08/02/2013","2:46 PM","<DIR>","","NT SERVICE\TrustedInsta","WinSxS"
"08/02/2013","2:46 PM","<DIR>","","NT SERVICE\TrustedInsta","System32"
"07/02/2013","1:39 AM","<DIR>","INSTAL~1 ","BUILTIN\Administrators ","Installer"
"05/02/2013","0:57 PM","<DIR>","AUINST~1 ","... ","AUInstallAgent"
"05/02/2013","9:07 AM","<DIR>","","NT SERVICE\TrustedInsta","inf"
"28/01/2013","6:38 PM","<DIR>","","NT SERVICE\TrustedInsta","twain_32"
"28/01/2013","6:38 PM","<DIR>","","BUILTIN\Administrators ","medias"
"28/01/2013","6:38 PM","<DIR>","","NT SERVICE\TrustedInsta","."
"28/01/2013","6:38 PM","<DIR>","","NT SERVICE\TrustedInsta",".."
"27/01/2013","3:00 AM","<DIR>","","NT AUTHORITY\SYSTEM ","assembly"
"21/01/2013","6:26 AM","<DIR>","","NT SERVICE\TrustedInsta","Fonts"
"13/01/2013","8:21 PM","<DIR>","","NT SERVICE\TrustedInsta","rescache"
"13/01/2013","6:20 PM","<DIR>","","NT SERVICE\TrustedInsta","WinStore"
"13/01/2013","6:20 PM","<DIR>","","NT SERVICE\TrustedInsta","ehome"
"28/12/2012","1:38 PM","<DIR>","TOASTD~1 ","NT SERVICE\TrustedInsta","ToastData"
"18/12/2012","1:16 AM","<DIR>","","NT AUTHORITY\SYSTEM ","Logs"
"13/12/2012","2:58 PM","<DIR>","","NT AUTHORITY\SYSTEM ","debug"
"02/12/2012","3:26 AM","<DIR>","","... ","Minidump"
"01/12/2012","6:48 PM","<DIR>","","NT AUTHORITY\SYSTEM ","Tasks"
"01/12/2012","6:48 PM","<DIR>","REGIST~2 ","BUILTIN\Administrators ","registration"
"01/12/2012","8:22 AM","<DIR>","","NT SERVICE\TrustedInsta","apppatch"
"22/11/2012","2:37 AM","<DIR>","POLICY~1 ","NT SERVICE\TrustedInsta","PolicyDefinitions"
"03/11/2012","4:30 AM","<DIR>","IMMERS~1 ","NT SERVICE\TrustedInsta","ImmersiveControlPanel"
"03/11/2012","4:28 AM","<DIR>","SOFTWA~1 ","BUILTIN\Administrators ","SoftwareDistribution"
"03/11/2012","1:50 AM","<DIR>","","NT AUTHORITY\SYSTEM ","Panther"
"03/11/2012","1:46 AM","<DIR>","","NT SERVICE\TrustedInsta","Media"
"03/11/2012","1:45 AM","<DIR>","DOWNLO~1 ","NT SERVICE\TrustedInsta","Downloaded Program Files"
"03/11/2012","1:44 AM","<DIR>","","NT SERVICE\TrustedInsta","schemas"
"03/11/2012","1:43 AM","<DIR>","LIVEKE~1 ","... ","LiveKernelReports"
"12/08/2012","9:38 AM","<DIR>","","BUILTIN\Administrators ","Sun"
"26/07/2012","7:27 PM","<DIR>","","NT SERVICE\TrustedInsta","ShellNew"
"26/07/2012","7:27 PM","<DIR>","","NT SERVICE\TrustedInsta","SKB"
"26/07/2012","7:27 PM","<DIR>","BITLOC~1 ","NT SERVICE\TrustedInsta","BitLockerDiscoveryVolumeContents"
"26/07/2012","7:27 PM","<DIR>","","NT SERVICE\TrustedInsta","security"
"26/07/2012","7:23 PM","<DIR>","DIGITA~1 ","NT AUTHORITY\SYSTEM ","DigitalLocker"
"26/07/2012","7:23 PM","<DIR>","SERVIC~1 ","NT SERVICE\TrustedInsta","servicing"
"26/07/2012","7:23 PM","<DIR>","","NT AUTHORITY\SYSTEM ","en-GB"
"26/07/2012","7:23 PM","<DIR>","","NT SERVICE\TrustedInsta","IME"
"26/07/2012","7:23 PM","<DIR>","","NT SERVICE\TrustedInsta","en-US"
"26/07/2012","7:23 PM","<DIR>","","NT AUTHORITY\SYSTEM ","Help"
"26/07/2012","5:53 PM","<DIR>","L2SCHE~1 ","NT SERVICE\TrustedInsta","L2Schemas"
"26/07/2012","5:53 PM","<DIR>","","NT SERVICE\TrustedInsta","addins"
"26/07/2012","5:53 PM","<DIR>","DESKTO~1 ","NT SERVICE\TrustedInsta","DesktopTileResources"
"26/07/2012","5:53 PM","<DIR>","","NT SERVICE\TrustedInsta","System"
"26/07/2012","5:53 PM","<DIR>","OFFLIN~1 ","NT SERVICE\TrustedInsta","Offline Web Pages"
"26/07/2012","5:53 PM","<DIR>","","NT SERVICE\TrustedInsta","Cursors"
"26/07/2012","5:53 PM","<DIR>","","NT AUTHORITY\SYSTEM ","SchCache"
"26/07/2012","5:53 PM","<DIR>","","NT SERVICE\TrustedInsta","Branding"
"26/07/2012","5:53 PM","<DIR>","","NT SERVICE\TrustedInsta","Boot"
"26/07/2012","5:53 PM","<DIR>","","NT AUTHORITY\SYSTEM ","TAPI"
"26/07/2012","5:53 PM","<DIR>","MODEML~1 ","... ","ModemLogs"
"26/07/2012","5:53 PM","<DIR>","","NT AUTHORITY\SYSTEM ","ELAMBKUP"
"26/07/2012","5:53 PM","<DIR>","RESOUR~1 ","NT SERVICE\TrustedInsta","Resources"
"26/07/2012","5:53 PM","<DIR>","","NT SERVICE\TrustedInsta","Web"
Re: Reading Columns & Output
Ok, After I added the HTML part, i get strange Output in the html file
Code: Select all
:: beginning of batch file
@Echo off
dir c:\windows\ /t:caw /x /q /a /o:-g-ds |find "/" > WinDir1.txt
:: code start to identify number of lines in a text
Set FileName=WinDir1.txt
Set /a LineNumb=0
for /f %%a in ('find /c /v "" ^< %FileName%') do set /a LineNumb=%%a
Echo %FileName% has %LineNumb% lines.
:: code end to identify number of lines in a text
setlocal enabledelayedexpansion
SET /A maxlines=116
SET /A linecount=0
del myResults.csv 2>nul
del Report.html 2>nul
FOR /F "delims=" %%b IN (WinDir1.txt) DO (
IF !linecount! EQU %maxlines% GOTO ExitLoop
set "field=%%b"
call :next "!field:~0,10!" "!field:~13,7!" "!field:~21,17!" "!field:~39,12!" "!field:~52,23!" "!field:~75!"
SET /A linecount+=1
)
:ExitLoop
del WinDir1.txt
:: end of subroutine
:: end of batch file
REM =============== HTML =======================
REM html file part 1
CALL :HTML_P1
REM html file rows
SETLOCAL EnableDelayedExpansion
For /F "tokens=1-6 delims=;" %%A In ('Type "myResults.csv"') Do (
SET "Date=%%A"
SET "Time=%%B"
SET "Type=%%C"
SET "Size=%%D"
SET "Owner=%%E"
SET "Name=%%F"
CALL :Row "!Date!" "!Time!" "!Type!" "!Size!" "!Owner!" "!Name!"
)
REM html file part 2
CALL :HTML_P2
pause
Exit /B
:HTML_P1
(
Echo ^<HTML^>
Echo ^<head^>
Echo ^<style media="screen" type="text/css"^>
Echo html {
Echo background-color: Black;
Echo color: Orange;
Echo }
Echo.
Echo table {
Echo border: 2px solid red;
Echo padding: 2px;
Echo }
Echo.
Echo td {
Echo width: 120px;
Echo height: 30px;
Echo border: 1px solid gray;
Echo }
Echo ^</style^>
Echo ^</head^>
Echo ^<body^>
Echo ^<table^>
)>>"Report.html"
GOTO :EOF
:Row <take_the_6_data_fields>
(
Echo ^<tr^>
Echo ^<td^>%~1^</td^>
Echo ^<td^>%~2^</td^>
Echo ^<td^>%~3^</td^>
Echo ^<td^>%~4^</td^>
Echo ^<td^>%~5^</td^>
Echo ^<td^>%~6^</td^>
Echo ^</tr^>
)>>"Report.html"
GOTO :EOF
:HTML_P2
(
Echo ^</table^>
Echo ^</body^>
Echo ^</html^>
)>>"Report.html"
GOTO :EOF
:next
set "line="
set c=0
:next2
set /a c=c+1
set tokens="tokens=*"
if %c% EQU 3 set tokens=
for /f %tokens% %%a in ("%~1") do call set line=%%line%%;%%a
shift
if not "%~1"=="" goto :next2
>> myResults.csv echo %line:~1%
Last edited by abc0502 on 13 Feb 2013 01:17, edited 1 time in total.
Re: Reading Columns & Output
After changing this line:
to This
and changing the delims in the for command that generate the html to ; it produce a readable table
changed the code above.
Code: Select all
for /f %tokens% %%a in ("%~1") do call set line=%%line%%,"%%a"
Code: Select all
for /f %tokens% %%a in ("%~1") do call set line=%%line%%;%%a
and changing the delims in the for command that generate the html to ; it produce a readable table
changed the code above.
Last edited by abc0502 on 13 Feb 2013 01:16, edited 1 time in total.
Re: Reading Columns & Output
The Problem now is in This, how to read the emptiness that exist between two semi-colon like this ";;" as the for loop read it as one. I remember something like that was discussed here before.