Solved

VBscript search for files

Posted on 2011-02-18
6
452 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
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:answer_dude
Comment Utility
where is spath getting set?
0
 
LVL 2

Author Comment

by:EfrenM
Comment Utility
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 500 total points
Comment Utility
Replace your objShell.run with this:
objShell.run "cmd /k" & " " & chr(34) & aItem.path & chr(34)

Open in new window

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Author Closing Comment

by:EfrenM
Comment Utility
worked perfectly thanks :)
0
 
LVL 10

Expert Comment

by:answer_dude
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

728 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

9 Experts available now in Live!

Get 1:1 Help Now