Solved

exiting a vbscript

Posted on 2014-03-13
7
247 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 49

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 49

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 49

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

825 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