Avatar of BlairBrenner
BlairBrennerFlag for United States of America

asked on 

How To Use The Folder Name In This Script

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
Visual Basic ClassicVB ScriptWindows XP

Avatar of undefined
Last Comment
RobSampson
Avatar of c0ldfyr3
c0ldfyr3
Flag of Ireland image

This should do it :)
sPath = Split(file, "\")
zzzz = sPath(UBound(sPath) - 1)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of game-master
game-master
Flag of Philippines image


good morning!


try this approach or add this on your code..
chrPath is the the full path you get
x is the last folder on the full path...

x = Mid(chrPath, Len(Mid(chrPath, 1, InStrRev(chrPath, "\") + 1)))



i hope this will give u idea..


game-master
Avatar of BlairBrenner
BlairBrenner
Flag of United States of America image

ASKER

I needed the final folder name, not the parent folder name.  So I just added
strFolderName = folder.Name
Otherwise works great!

Thanks
Avatar of RobSampson
RobSampson
Flag of Australia image

Oh yeah, good point!  I had ParentFolder stuck in my head after I thought you could just use objFile.ParentFolder, but then I thought you don't need that inside the loop, so I just used the objFolder, but didn't thnk that I didn't then need ParentFolder.Name...

At any rate, glad you got it working, and thanks for the grade.

Regards,

Rob.
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo