|
-
Nov 28th, 2006, 09:17 AM
#1
Thread Starter
Addicted Member
[RESOLVED]write/check file
Hello,
How can I make an .vbs file that does this:
Check if there is a hello.txt file with "hello" in it, if yes, give messagebox, if no, give messagebox and create/write the file.
A sort of cookie system in vbscript, but it wil not be used on the web, just on my computer.
Thanks in advance,
Thomas
Last edited by Mindstorms; Nov 17th, 2007 at 08:07 AM.
-
Nov 28th, 2006, 10:29 AM
#2
Hyperactive Member
Re: write/check file
VB Code:
'Code file for "hello.vbs"
Dim fso, flspec, fl, flcontents
'First create fso (FileSystemObject)
Set fso = CreateObject("Scripting.FileSystemObject")
'Now look for file C:\hello.txt
If fso.FileExists("C:\hello.txt") Then
'Get file to check size
Set flspec = fso.GetFile("C:\hello.txt")
If flspec.Size > 0 Then
'File size > 0 so file contains something
Set fl = fso.OpenTextFile("C:\hello.txt", 1, False)
flcontents = fl.ReadAll()
fl.Close
Else
'File size is 0 so nothing in file
flcontents = ""
End If
'Check file contents for "hello"
If flcontents = "hello" Then
'"hello" found
MsgBox("The file contatins hello!")
Else
'"hello" not found, but file exists
CreateHelloFile()
MsgBox("The file did not have hello in it.")
End If
Else
'"C:\hello.txt did not exist
CreateHelloFile()
MsgBox("The file did not exist.")
End If
'Kill all objects
Set fl = Nothing
Set flspec = Nothing
Set fso = Nothing
Function CreateHelloFile()
'Function that creates txt file C:\hello.txt and writes "hello" in it
Set fl = fso.OpenTextFile("C:\hello.txt", 2, True)
fl.Write("hello")
fl.Close
End Function
If this post helps, please RATE MY POST!
Using Visual Studio 2005 SE
-
Nov 28th, 2006, 11:08 AM
#3
Thread Starter
Addicted Member
Re: write/check file
Thank you!
-
Nov 28th, 2006, 02:11 PM
#4
Hyperactive Member
Re: write/check file
no problem, don't forget to mark the thread resolved.
If this post helps, please RATE MY POST!
Using Visual Studio 2005 SE
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|