Using the File System Object in Event Scripts

You can use the Visual Basic file system object to process files and folders. The following example uses the file system object to create a file and to copies the contents of an existing file to the new file.

-------------------------------------------------------------------
Sub AftExportToDat(strLoc, strCat, strPer, strTCat, strTPer, strFile)
‘------------------------------------------------------------------
‘ FDM EVENT Script: 
‘
‘Created By:  	Admin
‘Date Created: 	3/18/2004 4:17:58 PM
‘
‘Purpose: This script loops through the newly created Hyperion 
‘	 Enterprise .dat file And creates a new .dat file with
‘	 a different category and multiplies the amount by .75 
‘------------------------------------------------------------------
‘Declare local variables
Dim strline
Dim fso
Dim f1
Dim f2
Dim strNewFileName
Dim strEntity
Dim strAcct
Dim dblAmt

‘Declare file system object
Set fso = CreateObject(“Scripting.FileSystemObject”)

‘Open existing dat file for reading
Set f1 = fso.OpenTextFile(strFile, 1)

‘Create new .dat file with a “-FAS” suffix
strNewFileName=Left(strFile,Len(strFile)-4) & “-FAS” & Right(strFile,4)
Set f2=fso.CreateTextFile(strNewFileName,True)

‘Write category and beginning and ending periods to new file
f2.writeLine “FAS”
f2.writeLine strTPer
f2.writeLine strTPer

‘Skip first 3 header lines of existing dat file
f1.SkipLine
f1.SkipLine
f1.SkipLine

‘Loop through existing .dat file
Do While f1.AtEndOfStream <> True

‘Store line in a variable
 	strline = f1.ReadLine

 	‘Parse the entity from the line
 	strEntity = DW.Utilities.fParseString(strline, 3, 1, “,”)
  
 	‘Parse the account from the file
 	strAcct = DW.Utilities.fParseString(strline, 3, 2, “,”)

 	‘Parse the amount from the file 
 	dblAmt = DW.Utilities.fParseString(strline, 3, 3, “,”) 
 
 	‘Write out line to new .dat file but multiply amt by .75
 	f2.writeline strEntity & “,” & strAcct & “,” & dblAmt * .75
Loop

‘Close the files
f1.Close
f2.Close
 
‘Destroy file system object
Set fso=Nothing

End Sub
-------------------------------------------------------------------

See Appendix A for advanced information about scripting in FDM.