p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: FileSystemObject


Message #1 by "Fotopoulos, Lefteris" <LFot@e...> on Fri, 4 May 2001 15:13:53 +0300
OK,
i have the following filesystemobject functions.

Function CreateTempFile()

Function WriteTempFile()

Function ReadTempFile()

and Function Convert() which runs an .exe program which converts files
between Characters Sets.

The flow is like that:

1.Create a temp file with CreateTempFile() --> 2. Write a string to the temp
file with WriteTempFile() --> 3.Convert the temp file with Convert() --> 4.
Read the converted temp file with ReadTempFile()


All functions work OK, but the output of the ReadTempFile() is not the
converted file, but the first temp file created with CreateTempFile() and
WriteTempFile(). What i mean is that althought the converted temp file
exists(the converted file has the same name as the first file), the
ReadTempFile() function, reads from the first created temp file and not from
the converted file. I guess it cannot open the newest created(converted)
file. Why is this?



-------------------------Functions---------------------------------
Function Make_Tmp_File()

	Const TemporaryFolder = 2
	Set objFso = Server.CreateObject("Scripting.FileSystemObject")
	strTempFolder = objFso.GetSpecialFolder(TemporaryFolder)
	strTempFileName = strTempFolder & "\" & objFso.GetTempName()
	Set TempFile = objFso.CreateTextFile(strTempFileName)
	Make_Tmp_File = strTempFileName
	TempFile.Close
	Set objFso = Nothing

End Function



Function Write_Tmp_File(strTempFileName, strUTFstring)

Set objFso = Server.CreateObject("Scripting.FileSystemObject")
  If objFso.FileExists(strTempFileName) Then
        Set Txt = objFso.OpenTextFile(strTempFileName, 8)
        Txt.Write (strUTFstring)
        Txt.Close
        msg = 0
    Else
        msg = -1
    End If
    Set Sys = Nothing
    Write_Tmp_File = msg
End Function



Function Read_Tmp_File(strTempFileName)

Set objFso = Server.CreateObject("Scripting.FileSystemObject")
    If objFso.FileExists(strTempFileName) Then
        Set Txt = objFso.OpenTextFile(strTempFileName, 1)
        msg = Txt.ReadAll
        Txt.Close
    Else
        msg = "FAIL: File does not exist."
    End If
    Txt.Close	
    Set objFso = Nothing
    Read_Tmp_File = msg
    
End Function 


And runtime code
<%
strUTFstring = "some string"
strTempFileName = Make_Tmp_File()  ' Make a Temp File

x=Write_Tmp_File(strTempFileName, strUTFstring)  'Write string to Temp File 

Convert strTempFileName   'Convert the Temp File

Converted = Read_Tmp_File(strTempFileName)   'Read from the converted file

%>

The Converted String should hold the contents of the converted file, but
instead holds the contents of the first file with the unconverted data.

Sorry for the long post.
Any Ideas?
Thanks. 




  Return to Index