Script to find a variable in a path including sub directories

  • 929 Views
  • Last Post 10 February 2020
David Sladdin posted this 30 January 2020

Might be pushing the boat out a little bit here, but I have a potential client who would like to find a pre-existing folder by looking for a certain variable picked up with Zone OCR.

So say the Zone OCR picks up ABC123 - the software would then look in C:\Scans\ and all sub-directories to find the following folder C:\Scans\Joe Bloggs\Invoices\2019 ABC123\ and save the scan there.

I'm thinking some kind of script which takes the variable and does a search before filing the document in the matching folder name.

Dave.

Order By: Standard | Newest | Votes
luca.scarpati posted this 31 January 2020

Hi David,

 

good idea of development cool.

It's easy...You just need a script that searches for folders and returns to another variable the right folder with fully path.

 

Do not forget that you must always have a starting path and the necessary permission to search the specific path.

The workflow looks like this: 

...and attached the script.

 

Best regards,

Luca

 

Attached Files

  • Liked by
  • David Sladdin
David Sladdin posted this 31 January 2020

Hi Luca!

Many thanks for the fantastic speedy reply. I've put in the script block and pointed the script to the vbs file on my D drive. I think I'm missing how to get the folder path (FOLDER_PATH) out of the script as when I look in the log it states:

File destination path: '%FOLDER_PATH%\R2018.pdf'

So the file name is correct but the path is not. For the Windows File System output folder I have put %FOLDER_PATH%

Here is the script:

Option Explicit

on error resume next

 

Dim objFolder, objFSO, objSubFolder, iFolders

Dim variable

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

iFolders = 0

'variable = "ABC"

variable = Metadata.Values("TRAVIS_HAW_REF")

 

Call CheckFolders("D:\Output")

 

Sub CheckFolders(strPath)

    Set objFolder = objFSO.GetFolder(strPath)

        For Each objSubFolder In objFolder.SubFolders

                If (StrComp(objSubFolder.Name,variable) = 0) Then

call Application.Log(99, "Folder Found: " & objSubFolder.Path)

call Metadata.SetValues("FOLDER_PATH", objSubFolder.Path)

msgbox("Folder Found: " & objSubFolder.Path)

                End If

                Call CheckFolders(objSubFolder.Path)

        Next

If Err.Number <> 0 Then

msgbox "Error in CheckFolders:" & Err.Description

call Application.Log(99, "Error in CheckFolders:" & Err.Description)

Err.Clear

End If

End Sub

Can you see what I've done incorrectly?

Thanks again,

Dave.

David Sladdin posted this 31 January 2020

Never mind... I figure out I needed to change StrComp to InStr to find part of the directory path name, as below. Many thanks for your help! Pointed me in the right direction.

Option Explicit

on error resume next

 

Dim objFolder, objFSO, objSubFolder, iFolders

Dim variable

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

iFolders = 0

'variable = "R2018"

variable = Metadata.Values("TRAVIS_HAW_REF")

 

Call CheckFolders("D:\Output")

 

Sub CheckFolders(strPath)

    Set objFolder = objFSO.GetFolder(strPath)

        For Each objSubFolder In objFolder.SubFolders

                If (InStr(objSubFolder.Name,variable) <> 0) Then

call Application.Log(99, "Folder Found: " & objSubFolder.Path)

call Metadata.SetValues("FOLDER_PATH", objSubFolder.Path)

'msgbox("Folder Found: " & objSubFolder.Path)

                End If

                Call CheckFolders(objSubFolder.Path)

        Next

If Err.Number <> 0 Then

'msgbox("Error in CheckFolders:" & Err.Description)

call Application.Log(99, "Error in CheckFolders:" & Err.Description)

Err.Clear

End If

End Sub

  • Liked by
  • luca.scarpati
luca.scarpati posted this 31 January 2020

Hi David,

 

more than welcome and yes the Script was an example with StrComp but anyone can modify it according to their needs cool.

 

Best regards,

Luca

 

 

ianw4 posted this 07 February 2020

Hi

just trying to set this up on our system as it may work for one of our customers. thanks in advance.

in the windows file system path, I have the start of the path eg. 'c:\demonstration' a couple of folders down is the folder I want to drop the file into. so what do I need to put in the path as currently I have 'c:\demonstration\%FOLDER_PATH%' but this just creates a folder called 'FOLDER_PATH' ?

  • Liked by
  • luca.scarpati
luca.scarpati posted this 10 February 2020

Hi,

 

more than welcome for the script.

If you find a folder into "c:\demonstration\" with the name of the variable %FOLDER_PATH%, it means that no value has been assigned to it.

Where does it come from? are you sure you have assigned a correct value? Maybe try to export the variables.

 

Best regards,

Luca

ianw4 posted this 10 February 2020

Hi Luca

thanks for the response, I still have issues though.

output path is 'c:\demonstration\%FOLDER_PATH%'

the folder I am trying to output to is called 'kyocera' and is in 'c:\demonstration'

when I look in the logs I get the error 'the paths format is not supported'

the OCRZONE reads 'kyocera'

 

luca.scarpati posted this 10 February 2020

Hi,

 

your case is very specific and for sure your OCRZONE generates this error in the WFS because return invalid "path formats". Have you tried any other test documents? or have you tried with a static string inserted in the script?

 

Maybe execute an export of the workflow, take the debug logs, an example document that you use and open a ticket to our support support@scanshare.com.

 

Have a nice evening!

Luca 

 

Close