Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Script does not run

Posted on 2013-06-10
8
Medium Priority
?
435 Views
Last Modified: 2013-06-13
My vb script is supposed to list all filenames in a folder as defined by Path. Please help me figure out why the script isn't running.

Here's the script:
Option Explicit
Sub Main
   Dim Path
 Path = "\\domain-01.com\dfs$\care-one\users\care-one_nanthony\desktop\Report"
   Select Case WScript.Arguments.Count
      Case 0: Path = "*.*"             ' list current directory
      Case 1: Path = WScript.Arguments(0)
      Case Else: WScript.Echo "Invalid number of arguments.": Exit Sub
      End Select
   Dim a: a = ListDir(Path)
   If UBound(a) = -1 then
      WScript.Echo "No files found."
      Exit Sub
      End If
   Dim FileName
   For Each FileName In a
      WScript.Echo list.txt
      Next
 MsgBox "All Done!"
   End Sub
0
Comment
Question by:janthonyn
  • 4
  • 3
8 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 39235778
Do u get error or script simply does not outputs files?
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 39235799
Well, there seem to be a number of issues with that.

First, and a main issue, all your code is in the Main subroutine that is never executed.  Try removing the "Sub Main" and "End Sub" lines.

Also, you set Path to a long network drive location, but then never will use that, since you change Path to either "*.*" or the parm from the command line later.

Also, the Wscript.Echo should probably be displaying FileName, not list.txt.

~bp
0
 
LVL 58

Assisted Solution

by:Bill Prew
Bill Prew earned 2000 total points
ID: 39235899
Here's a working example that seems to do what you were looking for.

Option Explicit

Dim objFSO
Dim objFolder
Dim objFiles
Dim objFile
Dim strPath

strPath = "C:\EE"
Select Case WScript.Arguments.Count
   Case 0: 
      strPath = "."             ' list current directory
   Case 1: 
      strPath = WScript.Arguments(0)
   Case Else: 
      WScript.Echo "Invalid number of arguments."
      Wscript.Quit
End Select

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set objFiles = objFolder.Files
If objFiles.Count = 0 Then
   WScript.Echo "No files found."
Else
   For Each objFile in objFolder.Files
      Wscript.Echo objFile.Name
   Next
End If

Open in new window

~bp
0
Industry Leaders: 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!

 

Author Comment

by:janthonyn
ID: 39240968
billprew,

I tested the script you provided and it didn't work. No list was output. What I get is a series of popup screens with the title bar as - Windows Script Host. Each screen lists one filename in the body of the screen and an OK button. Press the OK button and you get the next screen with the name of another file in the folder. This loops until all the filenames in a folder are shown. I'm attaching one screen example.
Screen-example.PNG
0
 
LVL 58

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 39243276
Run from the command line as:

cscript yourname.vbs

~bp
0
 

Author Comment

by:janthonyn
ID: 39245712
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd ..

C:\Windows>cd ..

C:\>cd Reports

C:\Reports>cscript files.vbs
'cscript' is not recognized as an internal or external command,
operable program or batch file.

C:\Reports>cd ..

C:\>cscript Reports/files.vbs
'cscript' is not recognized as an internal or external command,
operable program or batch file.
0
 

Author Comment

by:janthonyn
ID: 39245928
it seems that the command prompt exe on my laptop isn't working correctly. I tried running the prompt as an administrator, but got the same results. I had someone else run the command on their laptop and the command was recognized. Thanks for your help on this. I need to find a better script, one that includes both folder path and output file path as set variables. That way I can save the script file anywhere. I ran the command with the script file in the same folder as the files I wanted listed.
0
 

Author Closing Comment

by:janthonyn
ID: 39245938
I still don't have the final solution. I want to be able to run the script from the vbs file and list the target folder path as a set variable in the script and have the output file created in a path also set in the script.

Nels
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

963 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