Some examples of using the File System Object

Click here to see MSDN documentation or for more info see this article Dim objFSO, objFolder Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder("C:\temp")
  • Loop Round files in folder For Each objFile in objFolder.Files Response.write objFile.Path Response.write objFile.Name Next
  • Read a file in one go Const fsoForReading = 1 Set objTextStream = objFSO.OpenTextFile("C:\temp\temp.txt",fsoForReading) strFileContents = objTextStream.ReadAll objTextStream.Close
  • Read a file line by line Const fsoForReading = 1 Set file = fso.GetFile(strFileName) Set objTextStream = file.OpenAsTextStream(fsoForReading) Do While Not textstream.AtEndOfStream response.write textstream.ReadLine Loop textstream.Close
  • Create and write to a file. Set textstream = objFolder.CreateTextFile("temp.txt") textstream.WriteLine ("temp temp temp temp temp ") textstream.WriteLine ("") textstream.WriteLine ("temp *temp *temp *temp *temp *temp *") textstream.WriteBlankLines (2) textstream.Close
  • Hosted by www.Geocities.ws

    1