Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

I need a script to check if file exists

Sep 17, 2008 10:30PM 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

- Collapse -
sorry I forgot to post the script
Sep 17, 2008 10:32PM 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
Sep 17, 2008 10:36PM 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
Sep 17, 2008 10:34PM 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