Sometimes a text file is preferred to a database. We can use text files to maintain one line of information or many lines. This tutorial will show you how use the File Scripting Object to both write to and append to a text file. Nothing could be easier.
Nuts Own Code

Asp Directory

Nuts Web Search
Web Directory
Web Search

Nuts ASP Code
Functions
Scripts
Tutorials
Wizards
Fonts
Download Fonts
Download Dll Files
Dll Files
Relaxing Games
Online Games
Take Our Poll
Do you use .Net?
Yes
No
Not Yet
Dot What?
Really, Take It!
Get The Source
About Nuts4Asp
Privacy
Contact Us
Arts
Movies, Television, Music
Business
Jobs, Industries, Investing
Computers
Internet, Software, Hardware
Games
Video Games, RPGs, Gambling
Health
Fitness, Medicine, Alternative
Home
Family, Consumers, Cooking
Kids and Teens
Arts, School Time, Teen Life
News
Media, Newspapers, Weather
Reference
Maps, Education, Libraries
Regional
US, Canada, UK, Europe
Science
Biology, Psychology, Physics
Sports
Baseball, Soccer, Basketball
World
Deutsch, Español, Français, Italiano, Japanese, Nederlands, Polska, Svenska
Help build the largest human-edited directory of the web
Now let's get down to it:

This is the code for APPENDING to a text file. This means what is already in the file will NOT be overwritten.

<%
Dim Stuff, myFSO, WriteStuff
'this is what we will write in the file
Stuff = "Here is some stuff to write in the file."
'this line creates an instance of the File Scripting Object named myFSO
Set myFSO = CreateObject("Scripting.FileSystemObject")
'this line opens the file, notice the 8, it will cause the script to append to the file
Set WriteStuff = myFSO.OpenTextFile("C:\Inetpub\wwwroot\myNewFolder\myNewText.txt", 8, True)
'this line actually writes STUFF from above to the file
WriteStuff.WriteLine(Stuff)
'
'this line closes the file
WriteStuff.Close
'this line destroys the instance of the File Scripting Object named WriteStuff
SET WriteStuff = NOTHING
'this line destroys the instance of the File Scripting Object named myFSO
SET myFSO = NOTHING
%>

This is the code for WRITING to a file. It will do just the opposite of the above. It will OVERWRITE anything already in the file.

<%
Dim Stuff, myFSO, WriteStuff
'this is what we will write in the file
Stuff = "Here is some stuff to write in the file."
'this line creates an instance of the File Scripting Object named myFSO
Set myFSO = CreateObject("Scripting.FileSystemObject")
'this line opens the file, notice the 2, it will cause the script to write to the file (overwriting existing text)
Set WriteStuff = myFSO.OpenTextFile("C:\Inetpub\wwwroot\myNewFolder\myNewText.txt", 2, True)
'this line actually writes STUFF from above to the file
WriteStuff.WriteLine(Stuff)
'
'this line closes the file
WriteStuff.Close
'this line destroys the instance of the File Scripting Object named WriteStuff
SET WriteStuff = NOTHING
'this line destroys the instance of the File Scripting Object named myFSO
SET myFSO = NOTHING
%>

To create a file look at this tutorial.
To create a folder in the same way look at this tutorial.
To delete a file look at this tutorial.
To delete a folder look at this tutorial.

Bad or missing query parameters in request.

Copyright © 2001-2008 Nuts4Asp.com
All other names used are property or copyright of their respective owners.