Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with creating a Log

Status
Not open for further replies.

simpsondm

IS-IT--Management
Jan 14, 2003
21
US
Below is a VBScript I’m using to copy a file and it works great but I need to add one feature, which I don’t know how to do. Can someone please help me? What I need it to do is this. After the file is copied add a line in a text file (logs.txt) stating completed with the date time and file name. If the file does exist or does not get copied put a note in the (Logs.txt) stating did not complete /copy files does exist add data and time. Have each entry added to the log.txt file on a new line.

Set Fso = CreateObject("Scripting.FileSystemObject")
Dim fso, fso2, dp, nx, i, File, Files, f


Set fso = CreateObject("Scripting.FileSystemObject")

fullfldr = "DC-FULL_GAO_TREE-" & MonthName(Month(now()), true) & "-" & DatePart("d", Date()) & "-" & DatePart("yyyy", Date())

'change folder structure
Set FldrObj = FSO.GetFolder("D:\Ecora\Auditor36\Novell\data\")

For Each objSubFolder In FldrObj.SubFolders

'change folder structure and change 58 to include additional folder lengths
if lcase(left(objSubFolder.Path,58)) = lcase("D:\Ecora\Auditor36\Novell\data\" & fullfldr) then
'msgbox lcase(left(objSubFolder.Path,58))
'Set FldrObj2 = FSO.GetFolder(objSubFolder.Path)
Dim a
Set a = fso.GetFile( objSubFolder.Path & "\csv")
a.Copy "d:\csv"

end if
next
 
Set up the logfile is simple.
[tt]
slogfile="c:\log\logfile.txt" 'your input
set ologfile=fso.opentextfile(slogfile,8,true)
'...etc the main job here
ologfile.close
set ologfile=nothing
[/tt]
Then the copy job is this.
[tt]
bFolder=false
For Each objSubFolder In FldrObj.SubFolders
'change folder structure and change 58 to include additional folder lengths
if lcase(left(objSubFolder.Path,58)) = lcase("D:\Ecora\Auditor36\Novell\data\" & fullfldr) then
[green]'no need of these[/green]
'msgbox lcase(left(objSubFolder.Path,58))
'Set FldrObj2 = FSO.GetFolder(objSubFolder.Path)
'Dim a
'Set a = fso.GetFile( objSubFolder.Path & "\csv")
'a.Copy "d:\csv"
bFolder=true
if fso.fileexists(objSubFolder.Path & "\csv") then
fso.filecopy objSubFolder.Path & "\csv", "d:\csv", true
ologfile.writeline now & " - folder found, file copied - " & objSubFolder.Path & "\csv"
else
ologfile.writeline now & " - folder found, file not found - " & objSubFolder.Path & "\csv"
end if
exit for 'no need to further looping
end if
Next
if not bFolder then
ologfile.writeline now & " - folder not found, file not found - " & objSubFolder.Path & "\csv"
end if
'close log file etc
[/tt]
That is about how it is done. It covers about all the basic need. You can modify the message to your complete satisfaction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top