Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBscript search for files

Posted on 2011-02-18
6
Medium Priority
?
463 Views
Last Modified: 2012-05-11
Hey guys

i get this script below and it works if the path doesnt have a space if it does it breaks at the first space can anyone give me a hint?
the echo looks fine but when i pass it to the cmd it looks like it breaks
Set objFSO = CreateObject("Scripting.FileSystemObject")
dim strdir

strDir = "F:\Data"
Set objDir = objFSO.GetFolder(strDir)
getInfo(objDir)

Sub getInfo(pCurrentDir)

For Each aItem In pCurrentDir.Files
 'wscript.Echo aItem.path
  Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "cmd /k" & " " & spath
Set objShell = Nothing
   
Next

For Each aItem In pCurrentDir.SubFolders
 '  wscript.Echo aItem.Name & " passing recursively"
   getInfo(aItem)
Next

End Sub

Open in new window

0
Comment
Question by:EfrenM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:answer_dude
ID: 34929423
where is spath getting set?
0
 
LVL 2

Author Comment

by:EfrenM
ID: 34929452
sorry forgot to remove that line i was testing something, here is the code
Set objFSO = CreateObject("Scripting.FileSystemObject")
dim strdir

strDir = "F:\Data"
Set objDir = objFSO.GetFolder(strDir)
getInfo(objDir)

Sub getInfo(pCurrentDir)

For Each aItem In pCurrentDir.Files
 'wscript.Echo aItem.path
  Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "cmd /k" & " " & aItem.path
Set objShell = Nothing
   
Next

For Each aItem In pCurrentDir.SubFolders
 '  wscript.Echo aItem.Name & " passing recursively"
   getInfo(aItem)
Next

End Sub

Open in new window

0
 
LVL 10

Accepted Solution

by:
answer_dude earned 2000 total points
ID: 34929550
Replace your objShell.run with this:
objShell.run "cmd /k" & " " & chr(34) & aItem.path & chr(34)

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Closing Comment

by:EfrenM
ID: 34929631
worked perfectly thanks :)
0
 
LVL 10

Expert Comment

by:answer_dude
ID: 34929791
Not sure exactly what you're trying to do... but this might work better (you won't have all those annoying command boxes...

set objShell = CreateObject("Shell.Application")
        objShell.Open aItem.path

Open in new window

0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 34931140
Not sure what you are trying to accomplish, but this can actually be done quite a bit easier with a BAT script.  This would do the same thing as the VBS script you are using:

@echo off
for /R "f:\data" %%A in (*.*) do "%%~A"

Open in new window

Just wanted to mention it in case it was of interest. For a little more flexibility you could also use the START command to run the files, like:

@echo off
for /R "f:\data" %%A in (*.*) do start "" "%%~A"

Open in new window

A number of options are available with the START command, do START /? from a command line to view them.

~bp
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

661 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