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

x
?
Solved

VBscript search for files

Posted on 2011-02-18
6
Medium Priority
?
465 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
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 59

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

926 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