Solved

output exception to txt file

Posted on 2007-11-21
7
387 Views
Last Modified: 2010-04-24
I have some code that copies the latest file found in a directory, i have the code looking through a series of subdirectories to find the newest file and then if the file contains todays date in the name then move it to a new loc, but i need to know if one or more of the latest files is not from today then output the file information to a txt file as an exception

code below
function getParent()
	fPath="D:\mySQLBackup"
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	Set oFolder = oFSO.GetFolder(fPath)
	set oSubfolders = oFolder.Subfolders
	
	for each oSubfolders in oSubfolders
		filePath=GetNewestFile(oSubfolders)
		if(instr(filePath, sToday)) then
			fileName = re.replace(GetFilenameFromPath(filePath),"")
			oFSO.CopyFile filePath , "D:\Backup\mySQLBackup\" & fileName , OverwriteExisting
		else
			 ' output data to "exception" & date() & ".txt"
		end if
	next 
end function

Open in new window

0
Comment
Question by:James Rodgers
  • 4
  • 3
7 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20329997
>' output data to "exception" & date() & ".txt"

simply could be:


Set objTextFile = oFSO.OpenTextFile _
(fPath & "exception" & date() & ".txt", ForAppending, True)
objTextFile.WriteLine("output data")
objTextFile.Close

Open in new window

0
 
LVL 25

Author Comment

by:James Rodgers
ID: 20330201
does the file need to exist or will this create it?
what happens on the next iteration when another exception is found? is it appended as a new line?
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 20330215
also, the code sample you have given wil put teh exception in the directory fpath, is there a system variable that will allow me to put it directly on teh desktop?


thanks
 
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20330227
what do you think the following parameters of oFSO.OpenTextFile will do:
ForAppending, True

anyhow, to clear any doubts:
http://www.w3schools.com/asp/met_opentextfile.asp
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 20330344
>>what do you think the following parameters of oFSO.OpenTextFile will do:
i'm not sure that's why i ASKED, for clarification, yes the append is clear, but not knowing any vbs how am i supposed to know what the true does?...oh yes i ASKED and got a facetious response, thanks
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20330361
glad I could help!
sorry for that, was actually intended "jokeful", looks like that did not get through ...
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 20330442
im sorry i took it the wrong way, i referenced this question to you as i respect your efforts on ee and i was a little shocked at the response

btw desktop variable
Set objShell = CreateObject("Wscript.Shell")
strFolder = objShell.SpecialFolders.Item("Desktop")

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question