Link to home
Start Free TrialLog in
Avatar of adirisin
adirisin

asked on

exiting a vbscript

Hi,

I have written a VB Script which scans a folder and moves the xlsx files to another folder ("input folder"), converts them into xls, invokes SAS, processes files and creates output. Once this is done, another script moves the files from "input folder" to an archive folder.

I wish to add a few lines to this script so that if there are no files in the folder, it should skip remaining pieces of code and exit the script.

Is it possible?

Regards,
Aditya
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adirisin
adirisin

ASKER

Thanks so much Rgonzo1971, it's working as expected.

Thanks again!
Hi Rgonzo1971,

Actually, the script exits if there are no files; however, it is exiting even if there are files. Please advise.

Thanks!
Then try

Path = "c:\*.xls*" ' looking for .xls* files

If Dir(Path) = "" Then
WScript.Quit
End If

Open in new window

Regards
Hey,

The query i wrote is:

Path = "C:\Users\aditya.kumar.vaish\Downloads\Trial_Runs\AUTO MATCH INPUT\*.xls*"

If Dir(Path) = "" Then
WScript.Quit
End If

However, I am getting an error stating

Type mismatch: 'Dir'.

The Data is invalid.
Hi,
this should be better

Path = "C:\Users\aditya.kumar.vaish\Downloads\Trial_Runs\AUTO MATCH INPUT\"
bFound = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(Path)
    For Each oFile In oFolder.Files
        If oFile.Name Like "*.xls*" Then
            bFound = True
        End If
    Next
if bFound = False Then WScript.Quit

Open in new window

EDIT Code corrected

Regards
Hi Rgonzo1971,

That's perfect!! It is doing exactly what I wanted. Thanks so much !!