Solved

VBscript search for files

Posted on 2011-02-18
6
456 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 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 53

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Recursive folder search vbscript 7 47
Added a column screws up code 5 57
Compile Error 7 51
How to read File Date Created using VB6 8 38
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

785 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