ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting folder paths (https://www.excelbanter.com/excel-programming/382455-getting-folder-paths.html)

dd

Getting folder paths
 
All,

I have the following line of code which gets the full path (iPath) of a file
(iFile) from a Root directory (sRoot)

Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1,
FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1))

I want to split it, so that the first folder in the path is displayed under
iPathCol1
and the remainder of the path is displayed in iPathCol2.

I don't understand the part after the equals sign!

Can provide a solution for me.

Thanks in advance.

DDawson



Bob Phillips

Getting folder paths
 
Presumably FindBack works from the end to find a \?

What is sRoot?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"dd" <dd.dd wrote in message ...
All,

I have the following line of code which gets the full path (iPath) of a

file
(iFile) from a Root directory (sRoot)

Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1,
FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1))

I want to split it, so that the first folder in the path is displayed

under
iPathCol1
and the remainder of the path is displayed in iPathCol2.

I don't understand the part after the equals sign!

Can provide a solution for me.

Thanks in advance.

DDawson





dd

Getting folder paths
 
Bob

sRoot is a string in the module code containing the startPath
startPath is also a string.

Function LoopFolders(startPath As String, _
Optional filetype As String = "RES File", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of Worksheet
iPathCol = Range("firstPath").Column
iFileCol = Range("firstFile").Column
iLinkCol = Range("firstLink").Column
iFile = Range("firstpath").Row
sRoot = startPath
'--
root is a named cell in the worksheet
path is a named cell in the worksheet

I think FindBack must find the first \ after the root, because there are
several backslashes in the path after the root.
I notice when I miss the \ after the root it adds it to the start of the
path cells. When I add the \ to the root it dissapears from the cells.


"Bob Phillips" wrote in message
...
Presumably FindBack works from the end to find a \?

What is sRoot?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"dd" <dd.dd wrote in message ...
All,

I have the following line of code which gets the full path (iPath) of a

file
(iFile) from a Root directory (sRoot)

Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1,
FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1))

I want to split it, so that the first folder in the path is displayed

under
iPathCol1
and the remainder of the path is displayed in iPathCol2.

I don't understand the part after the equals sign!

Can provide a solution for me.

Thanks in advance.

DDawson






Bob Phillips

Getting folder paths
 
I thought it was something like that. So isn't sRoot the first folder that
you want?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"dd" <dd.dd wrote in message ...
Bob

sRoot is a string in the module code containing the startPath
startPath is also a string.

Function LoopFolders(startPath As String, _
Optional filetype As String = "RES File", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of

Worksheet
iPathCol = Range("firstPath").Column
iFileCol = Range("firstFile").Column
iLinkCol = Range("firstLink").Column
iFile = Range("firstpath").Row
sRoot = startPath
'--
root is a named cell in the worksheet
path is a named cell in the worksheet

I think FindBack must find the first \ after the root, because there are
several backslashes in the path after the root.
I notice when I miss the \ after the root it adds it to the start of the
path cells. When I add the \ to the root it dissapears from the cells.


"Bob Phillips" wrote in message
...
Presumably FindBack works from the end to find a \?

What is sRoot?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my

addy)

"dd" <dd.dd wrote in message

...
All,

I have the following line of code which gets the full path (iPath) of a

file
(iFile) from a Root directory (sRoot)

Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1,
FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1))

I want to split it, so that the first folder in the path is displayed

under
iPathCol1
and the remainder of the path is displayed in iPathCol2.

I don't understand the part after the equals sign!

Can provide a solution for me.

Thanks in advance.

DDawson








dd

Getting folder paths
 
Bob

sRoot is the value that I type into the worksheet in the cell named "root"

The full path is input in the worksheet the the cell named "firstPath"

Instead of havingthe full path in one cell I would like to break it so that
the first directory (after the root) is input in a cell named firstPath and
the remainder of the path is input in the next cell named secondPath.

Regards
Dylan

"Bob Phillips" wrote in message
...
I thought it was something like that. So isn't sRoot the first folder that
you want?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"dd" <dd.dd wrote in message ...
Bob

sRoot is a string in the module code containing the startPath
startPath is also a string.

Function LoopFolders(startPath As String, _
Optional filetype As String = "RES File", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of

Worksheet
iPathCol = Range("firstPath").Column
iFileCol = Range("firstFile").Column
iLinkCol = Range("firstLink").Column
iFile = Range("firstpath").Row
sRoot = startPath
'--
root is a named cell in the worksheet
path is a named cell in the worksheet

I think FindBack must find the first \ after the root, because there are
several backslashes in the path after the root.
I notice when I miss the \ after the root it adds it to the start of the
path cells. When I add the \ to the root it dissapears from the cells.


"Bob Phillips" wrote in message
...
Presumably FindBack works from the end to find a \?

What is sRoot?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my

addy)

"dd" <dd.dd wrote in message

...
All,

I have the following line of code which gets the full path (iPath) of a

file
(iFile) from a Root directory (sRoot)

Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1,
FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1))

I want to split it, so that the first folder in the path is displayed

under
iPathCol1
and the remainder of the path is displayed in iPathCol2.

I don't understand the part after the equals sign!

Can provide a solution for me.

Thanks in advance.

DDawson









dd

Getting folder paths
 
Bob,

Function FindBack(text As String, char As String) As Long
Dim i As Long

' This is the InstRev emulator, it works backwards along a string
' to find a specified character.
For i = Len(text) To 1 Step -1
If Mid(text, i, 1) = char Then
FindBack = i
Exit For
End If
Next i
End Function

"Bob Phillips" wrote in message
...
Presumably FindBack works from the end to find a \?

What is sRoot?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"dd" <dd.dd wrote in message ...
All,

I have the following line of code which gets the full path (iPath) of a

file
(iFile) from a Root directory (sRoot)

Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1,
FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1))

I want to split it, so that the first folder in the path is displayed

under
iPathCol1
and the remainder of the path is displayed in iPathCol2.

I don't understand the part after the equals sign!

Can provide a solution for me.

Thanks in advance.

DDawson






dd

Getting folder paths
 
Bob,

From the worksheet I've copied the present values as follows

The root is a constant and is currently:
P:\Jobs\5048337\Surveys\Trial Surveys\

The Path column contains various paths such as:
Cathcart (Glasgow) Signal Box\Proforma\Fabric\
There will always be three folders in this path.

The filenames are something like:
100205.pfm

To repeat what I'm trying to do, I want to create two columns for the paths.
So that the first part, i.e. the location (Cathcart...) is in the first
column (for Autofiltering)
and the remainder of the path is in the second.

I hope this gives you enough to be able to help me with this.

Dylan.

and the remainder is in the second column.
"Bob Phillips" wrote in message
...
I thought it was something like that. So isn't sRoot the first folder that
you want?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"dd" <dd.dd wrote in message ...
Bob

sRoot is a string in the module code containing the startPath
startPath is also a string.

Function LoopFolders(startPath As String, _
Optional filetype As String = "RES File", _
Optional subfolders As Boolean = True)

' Create named Ranges, for the appropriate columns in Row 8 of

Worksheet
iPathCol = Range("firstPath").Column
iFileCol = Range("firstFile").Column
iLinkCol = Range("firstLink").Column
iFile = Range("firstpath").Row
sRoot = startPath
'--
root is a named cell in the worksheet
path is a named cell in the worksheet

I think FindBack must find the first \ after the root, because there are
several backslashes in the path after the root.
I notice when I miss the \ after the root it adds it to the start of the
path cells. When I add the \ to the root it dissapears from the cells.


"Bob Phillips" wrote in message
...
Presumably FindBack works from the end to find a \?

What is sRoot?

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my

addy)

"dd" <dd.dd wrote in message

...
All,

I have the following line of code which gets the full path (iPath) of a

file
(iFile) from a Root directory (sRoot)

Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1,
FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1))

I want to split it, so that the first folder in the path is displayed

under
iPathCol1
and the remainder of the path is displayed in iPathCol2.

I don't understand the part after the equals sign!

Can provide a solution for me.

Thanks in advance.

DDawson










All times are GMT +1. The time now is 02:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com