Directory Folder Search

Directory Folder Search

Anonymous
Not applicable
2,288 Views
3 Replies
Message 1 of 4

Directory Folder Search

Anonymous
Not applicable

I am wondering if there is a way to use iLogic in:

 

1. searching the "N:\14projects" directory for a folder that contains "1499PAS"

2. return the string after the "-" i.e. "blah blah blah" see image below

 

1.bmp

0 Likes
Accepted solutions (1)
2,289 Views
3 Replies
Replies (3)
Message 2 of 4

LukeDavenport
Collaborator
Collaborator
Accepted solution

 

Hi PhilShields. I think this will work:

As you specified - the code will give you everything after the '-' in the folder name. If you've got multiple '-' characters in the folder name then it'll find the first one and give you everything after that. Makes sense?

Imports
System.IO Imports System.IO.File Dim EndOfFolderName As String
Dim StartOfFolderName As String = "1499PAS" Dim DirName As String
' Loop through all folders in the defined directory For Each dir As String In Directory.GetDirectories("N:\14projects")
Dim dirInfo As New DirectoryInfo(Dir) DirName = dirInfo.Name ' Check to see if the folder name starts with the defined text
If DirName.Contains(StartOfFolderName) Then ' Create a string containing folder name after the character '-'
EndOfFolderName = Right(DirName, Len(DirName) - DirName.IndexOf("-") - 2) MessageBox.Show(EndOfFolderName, "Title") End If Next
Message 3 of 4

Anonymous
Not applicable

Worked perfect thank you very much.

0 Likes
Message 4 of 4

LukeDavenport
Collaborator
Collaborator

My pleasure.

0 Likes