Windows Vista Forums

convert input file with list of paths+filenames output to list of

  1. #1


    williamkow Guest

    convert input file with list of paths+filenames output to list of

    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.


      My System SpecsSystem Spec

  2. #2


    ekkehard.horner Guest

    Re: convert input file with list of paths+filenames output to listof

    williamkow schrieb:

    > 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.
    >
    Use the .GetParentFolderName method of the FileSystemObject.

    demo script:

    Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )
    Dim aTests : aTests = Array( _
    "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" _
    )
    Dim sFSpec
    For Each sFSpec In aTests
    WScript.Echo sFSpec, "==>", goFS.GetParentFolderName( sFSpec )
    Next

    output:

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

      My System SpecsSystem Spec

  3. #3


    Mayayana Guest

    Re: convert input file with list of paths+filenames output to list of

    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.
    |



      My System SpecsSystem Spec

  4. #4


    ekkehard.horner Guest

    Re: convert input file with list of paths+filenames output to listof

    Mayayana schrieb:

    > 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
    If you compare the results of the goFS.GetParentFolderPath method
    and Mayayana's function GetParentFolderPath():

    M C:\Users\Thong\Desktop\adrbc.xls ==> C:\Users\Thong\Desktop
    F C:\Users\Thong\Desktop\adrbc.xls ==> C:\Users\Thong\Desktop

    M C:\adrbc.xls ==> C:\
    F C:\adrbc.xls ==> C:\

    M C:\dir1\dir2 ==> C:\dir1
    F C:\dir1\dir2 ==> C:\dir1

    M C:\dir1\dir2\ ==> C:\dir1
    F C:\dir1\dir2\ ==> C:\dir1\dir2

    M C:\ ==>
    F C:\ ==> C:\

    you may prefer using the method - much less work and more resonable
    results.

    [...]

      My System SpecsSystem Spec

convert input file with list of paths+filenames output to list of

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can the "now playing" list be retrieved if a file is accedentally opened, losing list tankman1989 Media Center 0 06 Sep 2009
format-list and output formatting Blake PowerShell 7 11 May 2009
Cannot delete filenames/paths too long!! Firecracker Vista file management 6 18 Apr 2009
insert filenames list into SQL Server tomek PowerShell 4 18 Jun 2008
Network List Service is missing from the list of services digital-flex Network & Sharing 2 06 May 2008