Solved

exiting a vbscript

Posted on 2014-03-13
7
248 Views
Last Modified: 2014-03-13
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
0
Comment
Question by:adirisin
  • 4
  • 3
7 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39926173
Hi,

pls try

Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(path)) = False Then
WScript.Quit
End If

Open in new window

Regards
0
 

Author Closing Comment

by:adirisin
ID: 39926209
Thanks so much Rgonzo1971, it's working as expected.

Thanks again!
0
 

Author Comment

by:adirisin
ID: 39926447
Hi Rgonzo1971,

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

Thanks!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39926504
Then try

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

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

Open in new window

Regards
0
 

Author Comment

by:adirisin
ID: 39926579
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.
0
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39926681
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
0
 

Author Comment

by:adirisin
ID: 39927055
Hi Rgonzo1971,

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question