Solved

exiting a vbscript

Posted on 2014-03-13
7
242 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 48

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 48

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 48

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now