Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Useing FileSystemObject not working!

    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

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

    Code:
    <% 
    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.
    Omnis mico antequam dominus Spookster!

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •