...

View Full Version : Useing FileSystemObject not working!



Crash1hd
02-10-2003, 10:27 AM
Ok the following code I am trying to use is below grabbed straight from the devguru site but it doesnt seem to be working on my site I have made sure that reading and writing is enabled for everyone on that page! Why doesnt this code work for me!
<%
dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\test\somefile.txt", True)
path = filesys.GetAbsolutePathName("c:\test\somefile.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine("Your text goes here.")
filetxt.Close
If filesys.FileExists(path) Then
Response.Write ("Your file, '" & getname & "', has been created.")
End If
%>

Anythoughts!

Adam

Mhtml
02-10-2003, 10:47 AM
I'm not sure about some of the commands in that script. They seem to be pointless. I'm short on time at the moment so I'll have to leave the explanation to someone else.



<%
dim filesys, filetxt, getname, path
Set filesys = Server.CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\somefile.txt")
filetxt.WriteLine("Your text goes here.")
filetxt.Close
%>


That will work.

Crash1hd
02-10-2003, 11:46 AM
You say that should work yet I try it and well i wait and wait and the page never loads and I have to reset the IIS server so that I can view any asp page again! What am I doing wrong?

the script


<html><head><title>New Page 1</title></head>

<body>

<%
dim filesys, filetxt, getname, path
Set filesys = Server.CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\somefile.txt")
filetxt.WriteLine("Your text goes here.")
filetxt.Close
%>


</body>

</html>

arnyinc
02-10-2003, 03:00 PM
For testing purposes I would create a new directory and give "Everyone" full access to it. Make sure there are no files in the directory (or make sure you can overwrite/append to it) and test it that way.

Crash1hd
02-10-2003, 10:34 PM
Yep did that no change! its very wiered I wish I new why lol :)

the following code does work but the one above still doesnt


<html>
<body>

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

If (fs.FileExists("c:\1.txt"))=true Then
Response.Write("File c:\1.txt exists.")
Else
Response.Write("File c:\1.txt does not exist.")
End If

set fs=nothing
%>


</body>
</html>

whammy
02-11-2003, 01:21 AM
A pretty comprehensive resource for FileSystemObject is here:

http://www.w3schools.com/asp/asp_ref_filesystem.asp

I learned just about everything I know about FileSystemObject from that site and just playing around with it...

I actually use it somewhat extensively at work to "reformat" comma-delimited text files received from clients before importing them into SQL Server (to make sure there are the right number of fields, and no extra double quotes, etc.). For instance I'll split the lines of the text file into an array and check to make sure the UBound of the newly created array matches the correct number of fields (-1).

I also export data to them (they use an AS/400 database) after formatting it to their requirements - again using FileSystemObject. It isn't quite as fast as some other methods, but it works just fine, and in this case it's easier to make changes when required than some of the "faster" methods.

A lot of the code was already written by a former co-worker, but with the knowledge I've gained from the site above I have improved the code quite a bit.

P.S. check out the "List all files in a directory" sticky thread for some pretty cool recursive directory listing code from brainjar, once you're finished with w3schools. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum