We help IT Professionals succeed at work.
Get Started

How To Use The Folder Name In This Script

257 Views
Last Modified: 2010-04-30
I have a script that currently goes through all the subfolders in a path and executes a program using the file name obtained in the script for each iteration of a file in the subfolders.  What I would like to do is to also be able to use the subfolder name in each iteration.  Not the full path, just the name of the last folder in the path.  

ZZZZZ indicates where I want to use the folder name.

Thanks in Advance.

Here is the script:

Dim fso, WshShell, startFolder, targetApp, args1, args2

Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")

startFolder = "L:\Junk\02_Split Input\Test1"
targetApp = Chr(34) & "C:\Program Files\EMC Captiva\QuickScan\quickscn.exe" & Chr(34)
args1= " /cmd /open filename="
args2= "/foldername="
args3= " /startip deskew:operatingmode=detectangleanddeskew,direction=both,fillcolor=white,mode=text /exit"

SearchForFiles startFolder

Function SearchForFiles(folderName)
    Dim folder, file, fileCollection, folderCollection, subFolder, oExec

    Set folder = fso.GetFolder(folderName)
    Set fileCollection = folder.Files
    For Each file In fileCollection
      Set oExec = WshShell.Exec(targetApp & args1 & Chr(34) & file.Path & Chr(34) & args2 & ZZZZZ & Chr(34) & args3)
      Do While oExec.Status = 0
         WScript.Sleep 100
      Loop
    Next

    Set folderCollection = folder.SubFolders
    For Each subFolder In folderCollection
       SearchForFiles subFolder.Path
    Next
End Function
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE