Web Hosting, Design, & Coding forum

General discussion

I need a script to check if file exists

by ratfink1 / September 17, 2008 10:30 PM PDT

I need a script to check if a file exists and if so to write the information to an excel sheet. I have the below script that I've used to tell me a users pc name username and Lotus Notes version. If I could just add to it, to check if a certain file exists under c:\Documents and Settings\*user*\Application Data\Microsoft\Word\STARTUP and if so say yes or no.

Discussion is locked
You are posting a reply to: I need a script to check if file exists
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: I need a script to check if file exists
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
sorry I forgot to post the script
by ratfink1 / September 17, 2008 10:32 PM PDT

Option Explicit

Dim user, pc, notesversion
Dim fso, wsshell, logfile, WshNetwork

Set fso = createobject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

On Error Resume Next
Set logfile = fso.opentextfile("c:\Documents and Settings\gkj\Desktop\inventory.xls", 8, True)

While Err.Number <> "0"
On error Resume Next
Set logfile = fso.opentextfile("c:\Documents and Settings\gkj\Desktop\inventory.xls", 8, True)
Wend

user = WshNetwork.Username
pc = WshNetwork.ComputerName
If fso.fileexists("C:\lotus\notes\notes.exe") Then
notesversion = fso.GetFileVersion("C:\lotus\notes\notes.exe")
Else
notesversion = "Not Installed"
End If

logfile.writeline date & " " & time & "," & user & "," & pc & "," & notesversion

Set fso = Nothing
Set wshnetwork = Nothing
Set logfile = Nothing

Collapse -
Looks ok. But it's odd
by R. Proffitt Forum moderator / September 17, 2008 10:36 PM PDT

For you to ask for a script then post it. Maybe you were unclear and you didn't need a script but wanted someone to debug your code?

Collapse -
Not writing it for you but
by R. Proffitt Forum moderator / September 17, 2008 10:34 PM PDT

The if exist is a one liner.

http://www.google.com/search?hl=en&q=DOS+BATCH+IF+EXIST&btnG=Google+Search&aq=f&oq=

The next step to "write the information to an excel sheet" could be done with VBA. But since you have to use VBA why not just stick the whole thing in your VBA code? IF EXIST() is present in VBA so why not do that?

Again, I make no offer to write your code. Only to provide you with the facility or reference material so you can write it.
Bob

Popular Forums
icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

The Samsung RF23M8090SG

One of the best French door fridges we've tested

A good-looking fridge with useful features like an auto-filling water pitcher and a temperature-adjustable "FlexZone" drawer. It was a near-flawless performer in our cooling tests.