[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP delete file if already exists

Posted on 2006-05-18
7
Medium Priority
?
915 Views
Last Modified: 2008-03-06
I have an update page that writes field values to a text file.

If the text file exists, it should delete the existing file and create a new one
with the new values.

I am getting a need object error

here is my code

path = "C:/textfolder/"
path =path & stros

set fs = server.createobject("scripting.filesystemobject")

if fs.FileExists(path&".txt") then
   Set fileObject = fso.GetFile(path&".txt")
   fileObject.Delete
end if

set txt = fs.opentextfile(path&".txt",8,true,false)
txt.writeline strcmpname
txt.writeline stros
txt.writeline strBuild
txt.close
set fs = nothing
0
Comment
Question by:tmurray22
  • 4
6 Comments
 
LVL 3

Expert Comment

by:trainsdse
ID: 16711717
Change

set txt = fs.opentextfile(path&".txt",8,true,false)

TO

set txt = fso.opentextfile(path&".txt",8,true,false)
0
 
LVL 3

Expert Comment

by:trainsdse
ID: 16711723
SCRATCH THAT! ignore my comment
0
 
LVL 3

Expert Comment

by:trainsdse
ID: 16711766
Ok, your code works when I hard code the variables, see if this works:

path = "C:/textfolder/"
path =path & "bubba"

set fs = server.createobject("scripting.filesystemobject")

if fs.FileExists(path&".txt") then
   Set fileObject = fso.GetFile(path&".txt")
   fileObject.Delete
end if

set txt = fs.opentextfile(path&".txt",8,true,false)
txt.writeline "mycompany"
txt.writeline "bubba"
txt.writeline "mybuild"
txt.close
set fs = nothing

if so you have some un-populated variables, my guess would be the stros variable since it's used to make or get an object.

Thomas
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:tmurray22
ID: 16720901
got it to work like this


If (fs.FileExists (path&".txt"))= true  then

Set fileObject = (fs.GetFile(path&".txt"))
   fileObject.Delete


you put me on the right path(no pun intended)
0
 
LVL 3

Expert Comment

by:trainsdse
ID: 16720942
LOL, nice one, glad you got it worked out!

Cheers,

Thomas
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16982173
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 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