How to exit the code if the remote folder is not found. (1 Viewer)

Emmanuel

Master Tech
Local time
Today, 01:45
Joined
Sep 4, 2002
Messages
88
Hey guys,

I have this piece of code which works fine to pull the files from the remote server if the server is available. However, this server is taken down several times a week for back up and maintenance. My problem is that when this script runs and the server is down, I just get a "Path not found" error and the process stops. Can any of you help me with building something in there that says "If the path is not found, close the script"? :confused:

Thank you in advance for your help.

This is my code:

dim objFSO, f1, f, fc, strSourceFolder, strDestFolder, strlOOKFile, strlOOKFolder

'Constants
Const OverwriteExisting = TRUE

'Global variables

'********* This section for test only ****************
'strSourceFolder = "C:\Documents and Settings\intadmin\Desktop\ftp1\*.FLG"
'strlOOKFolder = "C:\Documents and Settings\intadmin\Desktop\ftp1\"
'********* Test section ends *************************

strSourceFolder = "\\tbstpabc\D\ftp1\*.FLG"
strlOOKFolder = "\\tbstpabc\D\ftp1\"
'strlOOKFile = "ISMSAGA.FLG"
strDestFolder = "C:\Documents and Settings\me\Desktop\ftp1\"


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set f = objFSO.GetFolder(strlOOKFolder)

Set fc = f.Files
For Each f1 in fc

If objFSO.GetExtensionName(lcase(f1.name)) = "flg" Then
objFSO.CopyFile strSourceFolder , strDestFolder , OverwriteExisting
Else
End If

Next
 

rainman89

I cant find the any key..
Local time
Today, 01:45
Joined
Feb 12, 2007
Messages
3,015
You might want to do an if the folder exists, anyone on the server, then run the code otherwise exit

if exists("\\server\folder\") then
run code
else
dont do anything
 

Emmanuel

Master Tech
Local time
Today, 01:45
Joined
Sep 4, 2002
Messages
88
Tried that. Doesn't work. I get "Type mismatch: 'exists'" error 800A000D


This is the code now:

dim objFSO, Dir, f1, f, fc, strSourceFolder, strDestFolder, strlOOKFile, strlOOKFolder

if exists("\\tbstpabc\D\ftp1\") then

'Constants
Const OverwriteExisting = TRUE

'Global variables

'********* This section for test only ****************
'strSourceFolder = "C:\Documents and Settings\me\Desktop\ftp1\*.FLG"
'strlOOKFolder = "C:\Documents and Settings\me\Desktop\ftp1\"
'********* Test section ends *************************


strSourceFolder = "\\tbstpabc\D\ftp1\*.FLG"
strlOOKFolder = "\\tbstpabc\D\ftp1\"
strDestFolder = "C:\Documents and Settings\me\Desktop\ftp1\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set f = objFSO.GetFolder(strlOOKFolder)

Set fc = f.Files
For Each f1 in fc

If objFSO.GetExtensionName(lcase(f1.name)) = "flg" Then
objFSO.CopyFile strSourceFolder , strDestFolder , OverwriteExisting
Else
End If
Next
ELSE
END IF
 

rainman89

I cant find the any key..
Local time
Today, 01:45
Joined
Feb 12, 2007
Messages
3,015
try something like

if Dir("\\tbstpabc\D\ftp1\")="" then
dont run
else
run
end if
 

Users who are viewing this thread

Top Bottom