Question : Dos & Vbs

Hi ,

Iam having a zip file.The script has to do following works
1)It needs to unzip that file
2)Under the files, many .csv files are present.
3)Script has to read each & every file and it needs to grep Dates in the files,Total lines in the files and it should be redirected to another file.All the files output should need to be append in 1 output file.


This will be tough to do in DOS.So vbs script can do this work easier.As iam new to vbs please explain briefly.

Answer : Dos & Vbs

try now:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
pathToZipFile="C:\temp\test.zip"
extractTo="C:\temp\unzip"

set fs = CreateObject("Scripting.FileSystemObject")
set objLog = fs.CreateTextFile("c:\temp\output.log")
	
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /c mkdir " & extractTo
Set oShell = Nothing

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.getfolder(extractTo)
For each oFile in  folder.Files
	oFile.Delete(True)
Next

set sa = CreateObject("Shell.Application")
set ns = sa.NameSpace(pathToZipFile)
set filesInzip = ns.items
sa.NameSpace(extractTo).CopyHere(filesInzip) 

EnumCSV extractTo

objLog.Close

sub EnumCSV(targetdir)
	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set folder = fso.getfolder(targetdir)
	For Each File in Folder.Files
		If fso.GetExtensionName(File)="csv"Then
			ParseCSV(File)		
		End If
	Next
end sub

sub ParseCSV(csv_file)
	set fs = CreateObject("Scripting.FileSystemObject")
	set objTextFile = fs.OpenTextFile(csv_file)
	dim arrStr,lines,lastdate,lasttime
	lines=0
	
	Do while NOT objTextFile.AtEndOfStream
		arrStr = split(objTextFile.ReadLine,",")
		lines=lines+1
	Loop
	
	lastdate = Replace(arrStr(0),"""","")
	lasttime = Replace(arrStr(1),"""","")
	
	objLog.WriteLine "File: " & csv_file
	objLog.WriteLine "Total Lines: " & lines
	objLog.WriteLine "Last date: " & lastdate
	objLog.WriteLine "Last time: " & lasttime
	objLog.WriteLine
	objTextFile.Close
end sub
Random Solutions  
 
programming4us programming4us