Solved

VBscript search for files

Posted on 2011-02-18
6
460 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 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 55

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

Technology Partners: 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!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

734 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