From: williamkow on
I have a text file containing a list of path or folder names and filenames,
and I wish to convert it to a list of path or folder name only -- using .vbs
language (wscript or cscript)

Example, the content of the input text file.

C:\Users\Alex\Desktop\abc.xls
C:\Users\Chong\Desktop\abc.xls
C:\Users\Mona\Desktop\abcDEX.xls
C:\Users\Siva\Desktop\abc.xls
C:\Users\Thong\Desktop\adrbc.xls

Output text file :

C:\Users\Alex\Desktop
C:\Users\Chong\Desktop
C:\Users\Mona\Desktop
C:\Users\Siva\Desktop
C:\Users\Thong\Desktop

Please use simple coding. Thank you very much in advance.

From: Mayayana on
Function GetParentFolderPath(path)
Dim Pt1, LenP
LenP = Len(path)
Pt1 = InstrRev(path, "\")
Select Case Pt1
Case 3
GetParentFolderPath = Left(path, Pt1) '-- C:\
Case LenP
GetParentFolderPath = Left(path, (len(path) - 1))
Case Else
GetParentFolderPath = Left(path, (Pt1 - 1))
End Select
End Function

In most cases you don't need all that -- if you
know you have valid file path strings in the first place.
If you're sure it's a file path and not on a root drive
then all you really need is:

Pt1 = InstrRev(path, "\")
GetParentFolderPath = Left(path, (Pt1 - 1))

The way I wrote the function it also deals with
a root drive/file such as: C:\file.txt

And it deals with a path like: C:\folder1\
by sending back: C:\folder1

|I have a text file containing a list of path or folder names and
filenames,
| and I wish to convert it to a list of path or folder name only -- using
..vbs
| language (wscript or cscript)
|
| Example, the content of the input text file.
|
| C:\Users\Alex\Desktop\abc.xls
| C:\Users\Chong\Desktop\abc.xls
| C:\Users\Mona\Desktop\abcDEX.xls
| C:\Users\Siva\Desktop\abc.xls
| C:\Users\Thong\Desktop\adrbc.xls
|
| Output text file :
|
| C:\Users\Alex\Desktop
| C:\Users\Chong\Desktop
| C:\Users\Mona\Desktop
| C:\Users\Siva\Desktop
| C:\Users\Thong\Desktop
|
| Please use simple coding. Thank you very much in advance.
|