Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If folder not exist

Status
Not open for further replies.

kippy13

IS-IT--Management
Aug 19, 2002
1,213
IE
Hi,
I have a simple problem (to most experts)
I have an existing script that I need to modify.
Basicilly, I want the script to check if a file exists (c:\windows\tools\filename.exe) and if it doesnt to copy the file from a location on the server to that location.
If the file does exist I just want the script to move onto the next line.
The next line of the script is to execute this file so the file needs to be on the machine.
Any ideas?
Kippy

***************************************
Looking for the best answers:
faq222-2244
Keeping your system clear of malware:
faq608-4650
***********************************
Dont forget to post back with the eventual resolution.
***************************************
 
[tt]set fso=createobject("scripting.filesystemobject")
if fso.fileexists("c:\windows\tools\filename.exe") then
'do something: file exists
else
'do something else: file does not exists
end if
[/tt]
 
This will do what you wanted:
Dim fso, WshShell, SourceFile, DestFile
DestFile = "c:\windows\tools\filename.exe" 'Local workstation file
SourceFile = "\\ServerName\ShareName\FileName.exe" 'Remote server file
Set fso = CreateObject("scripting.filesystemobject")
set WshShell = CreateObject("wscript.Shell")

If Not fso.FileExists(DestFile) Then
fso.CopyFile(SourceFile,DestFile)
End If
WshShell.Run(DestFile)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top